简体   繁体   中英

Extjs: Delete Row from store-> store.removeAt(RowIndex)

I have a bunch of RowIndexes from a store in my GridPanel. I want to delete these from my store. If I have only one, its no problem, the view from the Grid is refrsehd and the only entry is away.

But when I have more than 0ne, for example 10 RowIndexes and I make this in a loop like here...

for(rowIndex in indexes)
 {
    store.removeAt(indexes[rowIndex]);
 }

...only a few entries are deleted from the grid. I think the loop is too fast? I already treid it with a timeout, but doesn't work also. Is there anyone who has an idea? THANKS!!!

I would try to remove the rows in reverse order. Have you tried that? Something like

var i = indexes.length - 1;
for (; i >= 0; i--){
   store.removeAt(indexes[i]);
}

I know an answer has already been accepted, but I thought I'd add that calling Ext.data.Store#removeAt for each index will fire a datachanged event each time the method is called. If you have a datachanged listener, you may experience performance issues or unintended behavior. Since removeAt(index) is just a convenient alias for remove(getAt(index)) you can do this instead.

function batchRemoveAt(store, indexes) {
    var records = Ext.Array.map(indexes, function (index) {
        return store.getAt(index);
    });
    store.remove(records);
}

This will fire a single datachanged event for the entire remove, as well as the single remove events for each record removed.

try calling remove method of store which acceps Model instance or array of instances to remove or an array of indices from which to remove records.

store.remove([1,2,3]);

check docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM