“Create new version here”.http://zendgeek.blogspot.com/2009/07/create-dojo-grid-in-zend-framework-nice.html
About a month or two earlier when I used dojo calendar in my application and write article about the Zend Framework and dojo I was wondering why zend make collaboration with zend. But today when I created a grid using zend dojo I feel the real power of the dojo in Zend framework. In this article I am going to give a simple example and create a grid using Zend framework and dojo.
At the end of this tutorial we will have a grid like the following
So let’s feel the power of dojo in zend.
First execute the following query for creating a table.
CREATE TABLE ‘jobs’ (
‘id’ int(11) NOT NULL auto_increment,
‘title’ varchar(50) NOT NULL,
‘posted_date’ datetime default NULL,
PRIMARY KEY (‘id’)
This will create a table in your database.
Create a model in your models directory and write the following code in it
class Jobs extends Zend_Db_Table_Abstract
public function getJobsData()
$select = $this->_db->select()
$results = $this->getAdapter()->fetchAll($select);
and save this table as Jobs.php
In the code above, we first extend our model from Zend_Db_Table_Abstract, define its name and define our custom function getJobsData() that fetch all the rows in the jobs table. We return the results as an array.
Next create a controller JobsController in you controller’s directory and place the following code in it.
class JobsController extends Zend_Controller_Action
public function viewAction()
public function recordsAction()
$jobs = new Jobs();
$dojoData= new Zend_Dojo_Data(‘id’,$data,’id’);
In the above code we create two action view and records. We have placed nothing in the view action. In the recordsAction, we create an instance of Jobs model class.and then call its getJobsData() method which will give us an array of records. Next we create an instance of Zend_Dojo_Data() and give the fetched data to it. And finally we echo the data converted it into the Json.
We don’t need to create a view for the records action because we have placed exit it the end of this action which will stop rendering of the view. As we will call this action form our grid view template page so no need to define phtml file for it.
However we will need to create template file for our viewAction. In scripts/views/ directory create view.phtml file and place the following code in it.
<div dojoType=”dojox.data.QueryReadStore” jsId=”activeStore”, url=”records”></div>
<div dojoType=”dojox.grid.data.DojoData” jsId=”model” rowsPerPage=”20″ store=”activeStore”></div>
<table id=”activePastes” dojoType=”dojox.grid.Grid” model=”model” style=”height:300px; width:700px;”>
Keep in mind this is the main template file where we are creating our gird.
To include specific dojo js modules.
In the body tag I specify a class “tundra”. This is important for the stylesheet I have added.
Next tow div’s and table are the main code for creating grid.
The first div fetch the records from the url specified. This url may be different if you fetch records form the other controller or source. Please specify valid url otherwise you will not get what you want.
The next div act as a bridge between our first div and the table. This div take data from the first div and give it to the table for display purposes.
Keep in mind that all the attributes of the div’s and table are compulsory. Removing any of the attribute may result in unvalid records or empty page. So define everything that I have defined. Once you become able to display your records, you can play with these attributes.