Zwen2012
Zwen2012

Reputation: 3498

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!!!

Upvotes: 2

Views: 19892

Answers (3)

Eric
Eric

Reputation: 6995

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.

Upvotes: 4

toree
toree

Reputation: 437

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]);
}

Upvotes: 7

MMT
MMT

Reputation: 2216

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

Upvotes: 0

Related Questions