Search code examples
jsonrestdatagriddojotoolkit

How do I sort Dojo DataGrids based on dojo.store.jsonrest in the GUI without REST request?


I am currently implementing a frontend based on the Dojo Toolkit (1.6.1) receiving a lot of data from RESTful services. This is represented in the GUI by the dojox.grid.DataGrid using a dojo.store.JsonRest-store.

There are however operations used on the grid I do not wish to send a JSON request for, such as sorting a column. Is is possible to allow the user to sort the data without such a request? Can I cache the store information locally (e.g. user browser or in a file) to avoid this?

Any feedback you might have is very appreciated!


Solution

  • I facded the same issue and first tried dojo.store.cache, but this is not working. Hence I created my own cache usind a dojo.store.memory:

    startBuildingCache: function (url, idProperty) {
        try {
            var jsonStore = new dojo.store.JsonRest({ target: url });
            var jsonObjectStore = dojo.data.ObjectStore({ objectStore: jsonStore });
    
            var gotItems = dojo.hitch(this, function (items, request) {
    
                var dataStore = new dojo.store.Memory({
                    data: items,
                    idProperty: idProperty
                });
    
                this.cache = dojo.data.ObjectStore({ objectStore: dataStore });
                this.onCacheBuild({
                    src: this,
                    cache: this.cache
                });
            });
    
            jsonObjectStore.fetch({ onComplete: gotItems });
    
    
        } catch (e) {
            console.log(e.name + ": " + e.message);
        }
    },