Set data in dojo Store to rerender a grid

1.1k Views Asked by At

The problem is that I do not know how to update/rerender the store, datagrid or whatever that is involved in this process (the code is a little bit messy, but if there questions about it, please let me know)

In the old implementation (which works correctly), it was a filter with a textArea, and in this textArea there was limit of 100 ids that could be inserted and the query was created with them.

The ids where passed as parameters in the header of request (Get), and the data was correctly recovered and painted in the grid.

Here some parts of the code to understand better the problem.

First.js

            gridLiveView = new LiveViewTable({
                "storeLink" : 'monitor/store/communications',
                'query' : _filterWidgets.getStoredValues(),
                'useColumns' : [...]
            },


    on(selectButton, "click", function(event) {
                _filterWidgets.storeValues();
                gridLiveView.set('query', _filterWidgets.getStoredValues());

            });

LiveViewTable.js

function(...) {

var grid = declare([ SortFormatterGrid (Custom Grid) ], {

    refreshStore : null,
    cacheStore : null,

    constructor : function(args) {
        lang.mixin(this, args);

        // store definitions
        var _jsonStore = new SortFormatterJsonRestStore({
            idProperty : 'comId',
            target : this.storeLink
        });
        this.cacheStore = new SortFormatterMemoryStore({
            idProperty : 'comId'
        });
        this.store = new Observable(new Cache(_jsonStore,
                this.cacheStore));
        this.refreshStore = new SortFormatterJsonRestStore({
            idProperty : 'comId',
            target : this.storeLink
        });

_filterWidgets.getStoredValues() returns a map with the filter values.

The stores and the grid are custom stores, extended from (dojo/store/JsonRest and dgrid/OnDemandGrid)

Now, the situation has changed, instead of a limit of 100, the limit is 20000 ids. As a result of this, the header of the request is too long, and I get an error. That is why, it is tried another solution.

Instead of calling this on onClickEvent (gridLiveView.set('query', _filterWidgets.getStoredValues());), another method is implemented and called at the same level as the constructor in Second.js but without success.

The method which is called, Addition in LiveViewTable.js

update : function(queryMap) {
            var url = 'monitor/store/communications';
            xmlhttp = new XMLHttpRequest();
            xmlhttp.open("POST", url, false);
            xmlhttp.setRequestHeader("Content-type", "application/json");
            xmlhttp.send(JSON.stringify(queryMap));
            var data = JSON.parse(xmlhttp.responseText);
        }

That var data has the correct data that I want to show in the table. But I tried to set in this.store with a new Store, in this.data too, but the grid is always empty. Tried too this.refresh().

So the question is, what is what I have to do with the var data to show it content in the grid??

I tried things like this (without success):

this.data = data;

or

this.store = new Observable(new Memory({data: data}));
1

There are 1 best solutions below

2
On

You should be setting the new store via grid.set('store', ...), as mentioned in the documentation. Directly reassigning the store property doesn't give dgrid any way of knowing that the store actually changed.