PDA

View Full Version : Issue with using removeAll(true) on a container with 2 grids



abcdef
26 Sep 2011, 10:23 AM
I have a container that holds 2 grids tied to their respective stores. On itemselect, I need to remove both the grids and replace them with 2 other grids.

I have the 2 grids inside a container, and on select, I basically perform a removeAll(true) on the container, and add the 2 new grids. Everything works as expected, but the console throws the following error:



TypeError: 'null' is not an object (evaluating 'store.indexOf')


at ext-all-dev.js 124579:



// Provide indication of what row was last focused via
// the gridview.
onLastFocusChanged: function(oldFocused, newFocused, supressFocus) {
var views = this.views,
viewsLn = views.length,
store = this.store,
rowIdx,
i = 0;


if (oldFocused) {
rowIdx = store.indexOf(oldFocused);
if (rowIdx != -1) {
for (; i < viewsLn; i++) {
views[i].onRowFocus(rowIdx, false);
}
}
}


if (newFocused) {
rowIdx = store.indexOf(newFocused);


ext-all-dev.js:124579TypeError: 'null' is not an object (evaluating 'store.indexOf')



if (rowIdx != -1) {
for (i = 0; i < viewsLn; i++) {
views[i].onRowFocus(rowIdx, true, supressFocus);
}
}
}
},


Like I said, everything works as expected. But the console error persists. Can someone help me with this? Thanks...

skirtle
27 Sep 2011, 12:00 AM
From your description I'm assuming that you're destroying the same grid that fires the itemselect? Problem seems to be that at the point it fires that event it still has some other selection logic to do and if you destroy it that logic will fail.

There may be alternatives but I suspect the easiest way is just to defer your handler slightly. Maybe specify a delay or a buffer in the listener config?

abcdef
28 Sep 2011, 11:16 PM
From your description I'm assuming that you're destroying the same grid that fires the itemselect? Problem seems to be that at the point it fires that event it still has some other selection logic to do and if you destroy it that logic will fail.

There may be alternatives but I suspect the easiest way is just to defer your handler slightly. Maybe specify a delay or a buffer in the listener config?

Yep, adding the delay did work. Any pointers on how to accomplish removing a grid cleanly without the delay? The grid needs to get cleared out on an item select.

Thanks!

skirtle
30 Sep 2011, 3:13 AM
I don't much like the delay either but you're in a bit of a strange scenario so you might just have to tolerate it.

One alternative would be to go digging for a different event to listen on. There not be one late enough though.

Another option is to override some methods on the grid/view. For example, maybe you could replace onLastFocusChanged with Ext.emptyFn. Not convinced this is really neater than a delay though.