3
votes

I am using a dgrid OnDemandGrid to display data from a Dojo JsonRest store. This works well but I want the grid to automatically display changed data. Implementing a push-based approach where the server tells all clients which data has changed is too much effort, so I am looking for a client-based solution. Using dgrid's refresh() is not useful, since this causes flickering and resets the whole grid.

My best guess so far is to periodically fetch all data from a second store instance, compare this to the live store instance and use the Observable store wrapper to notify the grid of any changed data.

Is there a better, more elegant solution? If not, how do I do this best?

edit: The problem with this approach is to know which rows are currently displayed in the grid. My app works with large amounts of data so syncing the whole set in two dojo stores is not a good idea. Is there a way to tell which rows are currently displayed in the grid? Ideally, the grid would just periodically re-request data for the currently displayed rows. Can't be that hard, right?

edit2: My best approach so far is to "hack" the Observable store, keeping track of all calls to observe. I would then periodically re-execute the observed queries and merge changes into the live store. The problem is that dgrid keeps way too many observers open for this to work smoothly. It closes some of them, so there is no error in my code, and I set farOffRemoval to 500 (also tried lower and higher).

This is my code so far: https://gist.github.com/3225927

It's nowhere finished but it displays enough debug info to show where the problem is. Since probably nobody wants to set this up and there is no dgrid on jsfiddle, I can tell you that after some scrolling in a 1000 entry grid there are about 10-15 observers and observerStats.abs (count of all rows that are at least observed once) is about 750.

2
I'd be interested to hear if you've found a better solution, or if you're stilling using the Observable hack. I'm currently struggling with the same problem. - Frode
Yes I did, see my new answer for details. - user1252065

2 Answers

1
votes

You could use some CacheStore that you would simply flush (close/destroy) periodically

http://dojotoolkit.org/reference-guide/1.7/dojo/store/Cache.html

So basically, you clean the CacheStore, then redo your query.

0
votes

After many hours of thinking, I found a better solution to the problem: I create a Cache store, which is initially seeded with all database records (so this might not scale if you actually have millions of records). This Cache store is wrapped in an Observable store and updated by polling the server for changes (using plain HTTP with a Redis backend, nothing fancy like WebSockets or Comet).

Code: https://gist.github.com/anonymous/5003727