-->

Stateful server side filtering in dojo

2019-03-05 18:54发布

问题:

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 we need to use the URL parameter also, which according to documentation is

When both isServerSide and isStateful are true, this is a place to set the server url, if it cannot be retrieved by store.url.

I want to know how what is here store.url? I have searched in other sites, the other definition I get of url is from here and here

If using stateful, this is the url to send commands. default to store.url

Can anybody provide a simple example or demo on how to use isStateful property. I am pretty much confused here. Do we need to have server side scripting for this?

回答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();
         });