View Full Version : Store Index and View RowIndex Not in Sync

5 Jan 2012, 2:41 AM

I ran into a problem today after removing a proxy from my page. That proxy handled json mapping but because of new requirements that could result in the json having attributes that were nested but could now be null I got rid of the store and manually loop it to create model objects with a null check.

I have a grouped grid that uses the store and has a set of buttons in an action column.

To get the record that an action was performed on I could previously say

handler: function (grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);

But now that I manually add the records to the store after looping the JSON I get mismatches. The rowIndex does not match the Index of the correct record in the store.

Any hints of what I must consider?

As a dirty fix I figured that I could use

handler: function (grid, rowIndex, colIndex) {
var rec = grid.getView().getNode(rowIndex).children[0].textContent;

Not happy with this because it could create problems once the data is not in element 0 anymore due to other changes.

5 Jan 2012, 5:44 AM
I assume that the reason for this is that the array I add to the store is not grouped and the store itselft never applies the grouping definition to the order of the items while in the view the grid does do that which causes a mismatch of indexes.

Now how do I make sure that the objects in the store are sorted/grouped the same way they are displayed in the view.


I figured that explicitly calling the group(field,dir) method on the store everytime after I manually add records fixes my problem. I just assumed that given that the store itself was created with the group setting it would automatically apply this to added records, guess not.