PDA

View Full Version : The selected record did not updated after store reloaded



ragecf
29 Oct 2013, 11:28 PM
Hi, all

I selected one row in grid first, then modified back-end data and reloaded store. But the row kept selecting and the record data was not updated.

code:



Ext.onReady(function() {
var store = Ext.create('Ext.data.Store', {
fields:['name'],
autoLoad: true,
proxy: {
type: 'ajax',
url: 'data/grid.json',
reader: {
type: 'json',
root: 'root'
}
}
});

var grid = Ext.create('Ext.grid.Panel', {
title: 'Grid',
store: store,
height: 200,
width: 400,
columns: [
{ text: 'Name', dataIndex: 'name', flex:1 }
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [{
xtype: 'button',
text: 'Show Name',
scope: this,
handler: function(){
var rec = grid.getSelectionModel().getSelection()[0];
if(rec) {
alert(rec.data.name);
};
}
}]
}, {
xtype: 'pagingtoolbar',
store: store,
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});
})


data/grid.json


{total:2,root:[
{id:1,name: 'Lisa},
{id:2,name: 'Ian'}
]}


Test step:

1. Load grid and select row 'Lisa'
2. modify 'Lisa' to 'xxx' in grid.json
3. reload store (click refresh button on pagging toolbar)
4. The 'Lisa' was updated to 'xxx' in grid view, but the row was still selected.
5. click show name button, the display name was still 'Lisa' in alert window.

Is there any config or method to fix this issue?

PS: I found if there is no 'id' property in grid.json, the selected row will be deselected after store reloaded.

ragecf
30 Oct 2013, 5:53 PM
Ohhhhhhhhhhhhhh No!
Hit a bug: http://www.sencha.com/forum/showthread.php?261111

ragecf
30 Oct 2013, 11:52 PM
Any workaround?

scottmartin
31 Oct 2013, 1:14 PM
Do you have access to the nightly builds?

ragecf
31 Oct 2013, 5:06 PM
Do you have access to the nightly builds?

Sorry I did find it.

miran
21 Jan 2014, 12:31 PM
Try this:

store.load({grid.getSelectionModel().deselectAll();})