Shlomo
Shlomo

Reputation: 3990

ExtJs - keep grid row selected while edit

I change the value of the id column in my grid by listening to change of a textfield:

oTextfieldName.on( 'change', function( oField, strValue ) {
   oStore.getAt( 0 ).setId( strValue );
}

However, if setId() is called, the selection of that row 0 is removed. My app is dependent on that selected row to stay selected.

How can I keep the row selected, while still editing/changing that id column?


Edit:

When using store.sync() it gets back selected.

However, my store gets messed up throwing:

Uncaught TypeError: Object function () { this.destroy = Ext.emptyFn; } has no method 'indexOf' ext-dev.js:1253

Upvotes: 1

Views: 2209

Answers (2)

Shlomo
Shlomo

Reputation: 3990

Since sync() led to this error, I now use that poor way:

oSelectionModel.deselect( nIndex, true );        
oSelectionModel.select( nIndex, true );

After changing, I deselect (which is luckily invisible) and then select. At least it works.

Upvotes: 1

Justin
Justin

Reputation: 1310

Can you just re-select the row?

oTextfieldName.on( 'change', function( oField, strValue ) {
   oStore.getAt( 0 ).setId( strValue );
   yourGrid.getSelectionModel().select(0);
}

You could also do something like this to suppress the selection event from firing.

var suppressEvent = true;
yourGrid.getSelectionModel().select(rowIndex, null, suppressEvent);  

Check out the docs for the SelectionModel select method

Here is a simple fiddle you can play with. If you click the "Test" button it will select the row at index 1.

Upvotes: 2

Related Questions