Sunday, December 11, 2011

ExtJS - Performance Tuning - Multiple inserts in grid


- Copying the rows from the grid and inserting into same grid at position 0
- Copying or inserting rows at any location

While inserting the rows basically one will use below logic -
//r is record in below
foreach(..)
{
  r = ... store.insert(0, r);
}
however as you want to insert multiple rows in the grid, you are inserting rows into the store. Which will end up putting rows in the grid. You are missing one thing here, on each insert into the store, your grid will keep getting refreshed, which will end up in major delay in insert and performance glitch.

In order to have a quick/clean insert into the store, suspend the event on the store
store.suspendEvents(true);

//insert record in the store

store.resumeEvents();
It improves a performance, as grid is no longer getting refresh with each insert of row in the store.

You can perform the suspend at multiple places while doing calculations or validation on the grid, best thing to find out about this kind of performance issue is run the profiler, or perf. tuner while running the code. and find out which methods or events keep getting called.

No comments:

Post a Comment