PDA

View Full Version : extjs4 - bulk insert in store cause a performance issue



jpatel3
28 Nov 2011, 6:36 AM
Copying the rows from the grid and inserting into same grid in begining (insert at position 0).
It was causing performance issue, as soon as hits more than 10 rows. I started using
store.suspendEvents(true); foreach(..) { r = ... store.insert(0, r); } store.resumeEvents();
It improves a performance, as grid is no longer getting refresh with each insert of row in the store. however for some reason it throws exception while indexing the rows in the store. I think because store events are suspended, its going in some bad state.
fyi. its adding second row in the last again, where it throws with exception message.
Any other suggestion on how to handle this situation in any other way is welcome.

mitchellsimoens
28 Nov 2011, 6:52 AM
Where do you get an error? After inserting one record or after all have been inserted?

suspendEvents is the way to go to stop the grid from refreshing fro every insert.

jpatel3
28 Nov 2011, 7:10 AM
its after all rows inserted, it inserts 2nd row again in the end. and throws js error - 'internalId' is null or not an object

e.g.
1 test
2 test2
3 test3

if you copy this rows one by one and insert at 0th location


store.suspendEvents(true);

store.data.each(function(record){

var r = Ext.ModelManager.create(
{ .....},'Model');

store.insert(0,r);

});

store.resumeEvents();

---
result -
2 test2
3 test3
2 test2
1 test
1 test
2 test2
3 test3


extra record + script error.

am i doing something wrong while suspending event? also is there any better way to handle it?

jpatel3
29 Nov 2011, 12:18 PM
any help on this one?

tobiu
29 Nov 2011, 12:43 PM
i would definitely put all records you want to insert into an array first and then call store.insert(position, recordArray); once.