Querying JsonRest without HTTP requests for data

261 Views Asked by At

I'm using OnDemandGrid with JsonRest store to retrieve data from RESTful API and to show it on the table. The table is rather complex and all JsonRest CRUD methods are used. Here is the basic structure I'm using:

JsonRest:

...
var restStore = Observable(Cache(JsonRest({
    target:"source", 
    idProperty: "id"
}), Memory()));
...

OnDemandGrid:

...
var grid = new (declare([OnDemandGrid, Selection, Keyboard]))({
    sort: "name",
    store: restStore,
    columns: [
           {field: "name", label: "Name"},
           {field: "state", label: "State"},
           {field: "city", label: "city"}
         ],
    loadingMessage: "Loading data...",
    noDataMessage: "No data"
}, "grid");
grid.startup();
...

I want to filter the data on client side without sending HTTP requests. Can you give me some ideas to solve this issue?

Own resarch:

Dgrid tutorial stands on the fact that all depends on the dojo-store.

When dgrid interacts with a store, all paging, filtering, and sorting responsibilities fall upon the store, not the grid. ... When encountering data rendering issues, always check that the store implementation (and backend service, if applicable) are performing as expected.

So this means I have to resolve this issue on store side. I suppose, I have to extend QueryResults of JsonRest store but I am hitting the wall all the time.

I have also thought to query against Cache - but I loose the JsonRest then...

1

There are 1 best solutions below

2
On

If you're basically interested in initially retrieving a data payload from your service all at once up-front but then do all sorting/filtering/paging client-side, have a look at dojo-smore/RequestMemory - you pass it a url and it basically acts like a Memory store once it fetches data from the URL, except its methods return promises rather than immediate values.