Skip to content Skip to sidebar Skip to footer

Stateful Server Side Filtering In Dojo

I am doing server side filtering in the enhanced grid in dojo 1.10 version. Here in document it is clearly mentioned to use isStateful property. Also, if we use isStateful property

Solution 1:

require(['dojo/store/JsonRest',
        'gridx/Grid',
        'gridx/core/model/cache/Async',
        'gridx/modules/SingleSort',
        'gridx/modules/pagination/Pagination',
        'gridx/modules/CellWidget',
        'dijit/registry',
        'gridx/modules/Bar',
        'gridx/support/LinkPager',
        'gridx/support/Summary',
        'dojo/domReady!'],function(Store, Grid, Async, Sort, Pagination, CellWidget, registry, Bar, LinkPager, Summary){
    var jsonStore = new Store({
        idProperty: "id", target: <your url>,
                 query: function(query, options) {  
                     var request = {};              
                     /* Paging Params. */
                     if (grid==null) {   
                         /* null on first call to server. */
                         request.currentPage=0;
                         request.pageSize=DEFAULT_PAGE_SIZE;
                     } else {
                         request.currentPage=grid.pagination.currentPage();
                         request.pageSize=grid.pagination.pageSize();
                         if (request.pageSize==-1) {
                             /* Page size is -1 when 'ALL' records selected. Reset */
                              request.pageSize=DEFAULT_PAGE_SIZE;
                        }
                     }
                     /* Sorting Parameters. */
                     if (options.sort == null) {
                         /* null on first render. */
                         request.sortAttribute="id";
                         request.descending=false;
                     } else {
                        request.sortAttribute=options.sort[0].attribute;
                        request.descending=options.sort[0].descending;
                     }
                     var results = Store.prototype.query.call(this, request);   
                     return results;
                 }  
             });
             grid = new Grid({
                 cacheClass: Async,
                 store: jsonStore,
                 structure: <your column definition>,
                 barBottom: [{pluginClass: Summary, style: 'text-align: left;'},{pluginClass: LinkPager, style: 'text-align: right;'}],
                 modules:[Sort, Pagination, Bar, CellWidget]}); 
             grid.pagination.setPageSize(DEFAULT_PAGE_SIZE);
             registry.byId('gridDIV').set('content', grid);
             grid.startup();
         });

Post a Comment for "Stateful Server Side Filtering In Dojo"