0
votes

I'm deleting a row in a grid by getting its id and call a rest web service to delete it from database. The data grid is updated by the call of store.load(); The issue is that the record count never change unless I refresh the pages.

success : function (response) {
    console.log("count before load" + pDetailsTab.tvsListGrid.store.getCount());
    pDetailsTab.tvsListGrid.store.load();
    console.log("count after load " + pDetailsTab.tvsListGrid.store.getCount());
    if (pDetailsTab.tvsListGrid.store.getCount() >= 1) {
        console.log("inside if");
        pDetailsTab.tvsListGrid.getSelectionModel().select(0);
    } else if (pDetailsTab.respSGrid.store.getCount() >= 1) {
        pDetailsTab.respSGrid.getSelectionModel().select(0);
    }
    ExtjsUtils.hideWait();
}

Here is the output of console.log (I have replaced some output with '...'):

count before reload 1 ...
...
count after reload 1 ...

I've searched the internet but in vain. Any idea please?

3
I've used sync but in vain also. - Sofiane

3 Answers

1
votes

The issue is that load() is asynchronous. This code must be as follows :

pDetailsTab.tvsListGrid.store.load({
    scope: this,
    callback : function(records, operation, success) {
        console.log("count after load " + pDetailsTab.tvsListGrid.store.getCount());
        if (pDetailsTab.tvsListGrid.store.getCount() >= 1) {
            console.log("inside if");
            pDetailsTab.tvsListGrid.getSelectionModel().select(0);
        } else if (pDetailsTab.respSGrid.store.getCount() >= 1) {
            pDetailsTab.respSGrid.getSelectionModel().select(0);
        }
        ExtjsUtils.hideWait();
});

Please check the exjts doc of the version 4.1.3 http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-load

0
votes

Use grid's grid.getView().refresh() method or reload the grid's store by grid.getStore().reload()

0
votes

Are you getting correct records count from server? Try to debug the java code and also see query results. It can be the issue with java code which returns the records back.