Stateful server side filtering in dojo

眉间皱痕 提交于 2019-12-02 12:52:33
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();
         });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!