Dojo dGrid/dStore realtime update

1.7k Views Asked by At

I've been trying to get my dgrid/dstore grid in realtime. As var as I understand the function 'Observable' is deprecated, and also it doesnt work for me.

I've tried to update the grid via a Interval timer but then the whole grid is erased and new loaded. How to update the whole grid 'inline' without erasing, and showing 'loading data'?

This is my basic code:

var timer = setInterval(function() {
  store.invalidate(); // Invalidate the cache
  store.fetch(); // Perform a new request for all items
  grid.refresh(); 
}, 500);
1

There are 1 best solutions below

0
On

Observable does not exist in dstore, but there is a Trackable mixin which can be used instead. As for updating the grid when new content is fetch from the store, you could use a dstore/Cache and then pass the cached Memory store that mixes in Trackable to the grid to use instead. Each time new data is added to the caching store, it will also be reflected in the grid.

require([
    'dgrid/OnDemandGrid',
    'dstore/Rest',
    'dstore/Memory',
    'dstore/Trackable',
    'dstore/Cache',
    'dojo/domReady!'
], function (OnDemandGrid, Rest, Memory, Trackable, Cache) {
    var restStore = new Rest({
        target: '/mockRequest/'
    });

    var store = Cache.create(restStore, {
        cachingStore: new (Memory.createSubclass(Trackable))()
    });

    var grid = new OnDemandGrid({
        collection: store.cachingStore,
        columns: {
            id: 'ID',
            name: 'Name',
            description: 'Description'
        },
        loadingMessage: 'Loading...'
    }, 'main');
    grid.startup();

    setInterval(function () {
        store.fetch();
    }, 2000);
});