Search code examples
javascriptdojodgrid

Sitepen DGrid never queries for additional data on scroll


Background: I have an app that uses DGrid OnDemandGrid version 0.3.7 and works if I use a Memory Store with all the data stored in it. However, new requirements came in asserting that the backend store may have 400k+ rows in it. Hence I wrote a custom dojo store based on the JSonRestStore.

Problem: When the a user scrolls to the bottom of the grid, the Grid never requests new data of the store. I have made sure that the store returns a correct total

Observations The Grid looks for the preloaded data, there are 2 preload divs 1 above and 1 below the shown data. Both are empty and the top one is visible, bottom on is not. I saw some issues that were fixed dealing with this, hence I upgraded to 0.3.17, but the same problem persists. Would prefer not to move to 0.4.X because of the API change.

Question What would cause the scroll to never fire the request for data? The grid able to display the first request of data, it just never requests more.


Solution

  • This was extremely frustrating. In my custom store I was required to fetch data from a rest like endpoint, this returned a Deferred. However, I need to process the data returned data before returning it as a result. Hence I used the then() of the Deferred, which returns a Promise. Shouldn't be a problem... well it is Promises are sealed/frozen, hence you can't add the "total" to the object... which means total is set to the amount of data that is return.

    The fix I created a tracking deferred that is passed to QueryResults. I add the total deferred to this tracking deferred. My post processing then resolves the tracking deferred.