Friday, 13 July 2012

DOJO 1.7: DataGrid + JsonRestStore

Framework: SPRING 3.06 + DOJO 1.7

<script type="text/javascript">
function prepareDatagrid(){
require(['dojox/grid/DataGrid', 'dojox/data/JsonRestStore'],
   function(DataGrid, JsonRestStore)


gridLayout = [
             { name: 'Code', field: 'id.chmHouseCode', editable: true},
             { name: 'Name', field: 'chmHouseDesc'},
             { name: 'Capacity', field: 'chmCapacity'}];

var poStore = new JsonRestStore({target: "${urlCollegeHouses}/ajaxUnits/${hostelId}?" });

// use the query results returned from the server
/*create a new grid*/
   var grid = new DataGrid({
       id: 'grid',
       store: poStore,
       structure: gridLayout,
       rowSelector: '20px'});

   /*append the new grid to the div*/
   /*Call startup() to render the grid*/

Selain itu boleh guna kaedah manual fetching:

onComplete: function(items){
grid = new dojox.grid.DataGrid({
store: poStore,
items: items,
structure: gridLayout
}, "gridDiv");

No comments: