Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Check the default implementation of <a href="https://github.com/dojo/dojo/blob/master/store/Cache.js" rel="nofollow">Cache.js</a>, especially the <code>query</code> and <code>queryEngine</code> functions. By default they always get first to the master store, which in your case is the <code>JsonRest</code> store. Only after the data has been loaded, the caching store is updated (in your case the <code>Memory</code> store).</p> <p>Now, if you check function <code>_setSort</code> in DGrid <a href="https://github.com/SitePen/dgrid/blob/master/List.js" rel="nofollow">List.js</a> file, and function <code>refresh</code> in DGrid <a href="https://github.com/SitePen/dgrid/blob/master/OnDemandList.js" rel="nofollow">OnDemandList.js</a> you'll sill see that by default DGrid calls the <code>query</code> method of the current <code>store</code> to obtain the new list of items sorted differently. In your case that store is the <code>dojo/store/Cache</code>.</p> <p>So, summing up, when the user clicks the column to sort, DGrid queries the <code>Cache</code>, which in turn queries <code>JsonRest</code>, which in turns queries the server, which then returns new data, which then the <code>Cache</code> stores in the <code>Memory</code> store.</p> <p>You can actually confirm this for example with Firebug (a Firefox extension). In my case whenever I tried to sort, Firebug was showing a new request to the server to obtain new data.</p> <p>This makes sense when there are lots of rows because DGrid is designed to load only the first batch of rows and then update the grid when user scrolls down. When the sort is changing, the first visible batch of rows may be different and may not be loaded yet, so DGrid must load them first. </p> <p>But in my case the Json request was returning all data during a single request. I didn't like the default implementation and implemented my own caching store which doesn't require a trip to the server when changing the sorting. I can't share the implementation now but will try to do when I have some time to tidy up the code.</p> <p>As for now you shouldn't notice any performance problems if you switch to <code>JsonRest</code> store only (considering that when changing the sorting there is the trip to the server anyway).</p> <p>I am not sure what causes the specific problem of duplicated rows, but I remember seeing it too when my caching store wasn't implemented properly (it had something to do with deferred requests when loading data If I recall correctly). You can try to debug it by adding (again with Firebug) breakpoints in the <code>get</code> and <code>query</code> functions of the <code>Cache</code> store. My bet is that DGrid tries to load particular rows with the <code>get</code> method (which hits the cache) while the <code>query</code> request is still loading data from the server after user changed the sorting. But I may be wrong so please try to confirm it first if you can.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload