Is there any way to use query method with dstore?

192 views Asked by At

Earlier I was using below code. With this, the range(Say: range: items:0-49) added in request header and fetches the data based on it. See below:

    require(["dojo/_base/declare",
            "dgrid/Grid",
            "dojo/store/Memory",
            "dgrid/extensions/Pagination",
            "dgrid/extensions/ColumnResizer",
            "dgrid/extensions/ColumnHider",
            "dgrid/extensions/ColumnReorder",
            "dojox/data/QueryReadStore",
            "dgrid/extensions/DijitRegistry",
            "dojo/store/JsonRest",
            "dojo/store/util/QueryResults",
            "dgrid/editor",
            "dojo/store/Cache",
       ],
        function(declare, Grid, Memory, Pagination, ColumnResizer, ColumnHider, ColumnReorder, QueryReadStore, DijitRegistry, JsonRest, QueryResults, editor,Cache){
             var Store = new Cache( JsonRest({
             target: "/path/to/service",
             query: function(query, options) {
                    var results = this.inherited(arguments);
                    var total;
                    var deferred = results.then(function(result) {
                        total = result.numRows;             
                        return result.listOfItems;
                    });
                    var qr = new QueryResults(deferred);
                    qr.then(function(qr){
                        qr.total= total;
                    });

                    return qr;
                }
            }), new Memory() );


        var searchGrid = new  (declare([Grid, Pagination, Selection, ColumnReorder, ColumnResizer, ColumnHider, DijitRegistry]))({
                store: Store,             
                noDataMessage: "No data found",
                pageSizeOptions: [10, 15, 25], 
                rowsPerPage:10,
            }, "searchGrid");
            searchGrid.startup();

I have upgraded dgrid to 0.4., which uses dstore and only support a collection property. So I have replaced dojo/store with dstore and using dstore/RequestMemory with dgrid/OnDemandGrid'.

        var Store = new RequestMemory({
        target: "/path/to/service",
        });

        var searchGrid = new  (declare([Grid, Pagination, Selection, ColumnReorder, ColumnResizer, ColumnHider, DijitRegistry, selector, editor]))({
                collection: Store,
                noDataMessage: "No data found",
                pageSizeOptions: [10, 15, 25], 
                rowsPerPage:10,
            }, "searchGrid");
            searchGrid.startup();

dstore/RequestMemory is really more of a one-time request. So when the grid has less than 1000 records, its working correctly. But for greater than 2000 records, it is taking a lot of time to fetch records. I want to add the same query method with dstore. I mean how to update/replace this query method using dgrid 0.4. Please Suggest.Thanks!

0

There are 0 answers