Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically refresh dgrid contents

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.


1 Answers

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.

like image 100
PEM Avatar answered Mar 07 '26 17:03

PEM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!