2

I Have four grids in Dojo, all of which update with real time data every few seconds.

I only display one grid to the user at a time, but in the background all four grids update. This makes the page slow down a lot on a mobile device (not noticeable on a PC).

Is there a way to disable updating a grid if it's not in view?

var myGrid = new (declare([Grid, DijitRegistry]))({
    store: myStore, // this is a Observable(Memory())
    columns:[
        {field: "field1", label: "A", sortable: false},
        {field: "field2", label: "B", sortable: false},
        {field: "field3", label: "C", sortable: false},
        {field: "field4", label: "D", sortable: false},
        {field: "field5", label: "E", sortable: false}
    ],
    selectionMode: "single",
    cellNavigation: true,
    queryOptions: {
        sort:[{attribute: "field1", descending: true}]
    }
},
    myDomRef
);

is there something like

myGrid.disable();

and

myGrid.enable();

so that DOM updating only occurs if the Grid is enabled?

SoluableNonagon
  • 11,541
  • 11
  • 53
  • 98
  • Do you mean that the grid should stop being observable? – colecmc May 18 '15 at 22:14
  • Sure, that sounds like it might do the trick. – SoluableNonagon May 18 '15 at 22:25
  • Observables have a cancel method. That may work for your scenario. http://dojotoolkit.org/reference-guide/1.10/dojo/store/Observable.html – colecmc May 18 '15 at 22:28
  • Can you elaborate? I'm new to Dojo – SoluableNonagon May 18 '15 at 22:29
  • This may post may be helpful to figure out if your grid is in view: http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport – colecmc May 18 '15 at 22:41
  • That one doesn't help, it's just whether its in view, I already have a way to determine that. Your suggestion of making it for not observable is great, but I don't know how to do that. The previous link isn't too helpful either :(. – SoluableNonagon May 18 '15 at 22:44

2 Answers2

1

If you are using dgrid 0.3.17 or dgrid 0.4.0, there are options to enable/disable observation, but they only take effect at the time a store or collection is set.

In dgrid 0.3.17, the property is shouldObserveStore:

grid.set('shouldObserveStore', false);
grid.set('store', ...);

In dgrid 0.4.0, the property is shouldTrackCollection:

grid.set('shouldTrackCollection', false);
grid.set('collection', ...);
Ken Franqueiro
  • 10,559
  • 2
  • 23
  • 40
-1

Here is an example from their documentation page on Observables. I have NOT TESTED this but the idea should be the same you'll just have to work out the details.

require(["dojo/store/Observable", "dojo/store/Memory"], function (Observable, Memory) {
    var myGrid = new(declare([Grid, DijitRegistry]))({
            store: myStore, // this is a Observable(Memory())
            columns: [
                {
                    field: "field1",
                    label: "A",
                    sortable: false
                },
                {
                    field: "field2",
                    label: "B",
                    sortable: false
                },
                {
                    field: "field3",
                    label: "C",
                    sortable: false
                },
                {
                    field: "field4",
                    label: "D",
                    sortable: false
                },
                {
                    field: "field5",
                    label: "E",
                    sortable: false
                }
            ],
            selectionMode: "single",
            cellNavigation: true,
            queryOptions: {
                sort: [{
                    attribute: "field1",
                    descending: true
                }]
            }
        },
        myDomRef
    );
    // create the initial Observable store
    store = new Observable(new Memory({
        data: someData
    }));

    // query the store
    var results = store.query({
        rating: 5
    });

    // now listen for any changes
    var observeHandle = results.observe(function (object, removedFrom, insertedInto) {
        // do something
    });

    // done observing, any further modifications will not trigger our listener
    observeHandle.cancel();

});
colecmc
  • 3,133
  • 2
  • 20
  • 33
  • The grid will query the store and observe its results itself - performing additional queries / observations entirely outside the purview of the grid will not affect its own query/observation at all. – Ken Franqueiro May 18 '15 at 22:55