PDA

View Full Version : Issue with selectNext in GridPanel after deleting a row



himalpatel
5 Sep 2011, 1:50 AM
Hi,
I am new to sencha. and trying to achieve following.
On a button click event, I want to delete the current selected row from the grid and load the next row. Here is the code that i have written.
qItemGrid.store.remove(rowToDelete);
if(smObj.hasNext())
{ smObj.selectNext(false); }
This works fine, but it load skip one row every time. so If i have row as 1,2,3,4,5,6,7 then after 1st it will load 3rd row. after 3rd it will load 5th row.
Please help me get solution to this problem.
Thanks
Himal

skirtle
5 Sep 2011, 7:24 PM
Please use CODE tags when posting code (# button on the editor toolbar).

This appears to be an ExtJS 3 question. This forum is for ExtJS 4.

I assume when you say 'load' you mean 'select', otherwise I'm not sure what you mean.

My guess would be that your issue occurs because selectNext() increments the selection index whereas remove() implicitly reduces the indices for all the records that follow. The combined effect is an increase of 2.

I'd have thought that reversing the order would avoid the problem:


if (smObj.hasNext()) {
smObj.selectNext(false);
}

qItemGrid.store.remove(rowToDelete);

himalpatel
5 Sep 2011, 8:10 PM
Thanks for your prompt reply,
The issue persist even after changing the order of the operations.
What I have got is there is a .last and .lastActive property. which holds the value of the row index in the grid. when SelectNext happens it gets set properly. but during remove it doesn't decrease it and that is the root cause.
It seems that I must be missing something. not sure what exactly.

Thanks
Himal

skirtle
5 Sep 2011, 8:25 PM
I guess you could do this:


var selectedIndex = smObj.last;

qItemGrid.store.remove(rowToDelete);

smObj.selectRow(selectedIndex);

If you don't like using last (due to it being undocumented) then you can get the same value by getting the selected record and looking up its index in the store.

himalpatel
9 Sep 2011, 5:59 AM
Thanks for your reply, I will give it a go and let you know..

Thanks you,
Himal

himalpatel
12 Sep 2011, 11:51 PM
Thank you skirtle,
it worked!!

Himal

himalpatel
19 Sep 2011, 10:28 AM
need help, i upgraded my grid now from 3 to 4. and there is no hasprevious and hasnext functions. i tried searching a lot to find alternates. but couldn't. i also tried getting the index to check it against the length to decide. but index is returning -1 somehow. here is the code i use to find index.


var index=grid.store.indexOf(record);


Can you please let me konw what is the alternatives of those functions ?

Thanks
Himal