suamikim
suamikim

Reputation: 5319

ExtJS 4.1.1a: Item in grid is deselected after record has been modified with set-method

Hy there,

I have a very basic example with a grid with only 1 item and a button which updates this entry with the set-method of the underlying record.

The problem is, that if the item is selected at the time the record gets updated by pressing the button, the selection gets removed and it's not possible to select it anymore afterwards.

Working example: http://jsfiddle.net/fu2Xq/2/

Ext.onReady(function() {
    var personsGrid = Ext.create('Ext.grid.Panel', {
        width: 150,
        height: 100,
        renderTo: Ext.getBody(),

        store: Ext.create('Ext.data.Store', {
            fields: [ 'name' ],
            data: [{ name: 'Stephen' }]
        }),

        columns: [{ text: 'Name', dataIndex: 'name', flex: 1 }],
    });

    var txtField = Ext.create('Ext.form.field.Text', {
        fieldLabel: 'New name',
        labelWidth: 70,
        width: 150,
        value: 'Alex',
        renderTo: Ext.getBody()
    });

    Ext.create('Ext.button.Button', {
        text: 'Rename person',
        width: 150,
        renderTo: Ext.getBody(),
        handler: function() {
            var rec = personsGrid.getStore().getAt(0);

            rec.set('name', txtField.getValue());
        }
    });
});

Seems like a bug to me because after reordering the name-column the selection reappears...

I'd really appreciate some comment on this!

Thanks


edit: reformated some code...

Upvotes: 1

Views: 1404

Answers (2)

suamikim
suamikim

Reputation: 5319

It's a bug in ExtJS 4.1.1 which seems to be solved in 4.1.3 and can be worked around by calling the refresh-method of the grid's view after updating the record:

http://jsfiddle.net/fu2Xq/7/

handler: function() {
    var rec = personsGrid.getStore().getAt(0);

    rec.set('name', txtField.getValue());  
    personsGrid.getView().refresh();
}

I got this answer from the Sencha forum: http://www.sencha.com/forum/showthread.php?253287-Item-in-grid-is-deselected-after-record-has-been-modified-with-set-method&p=928197&viewfull=1#post928197

Upvotes: 1

Avinash T.
Avinash T.

Reputation: 2349

On headerclick event of column headers, old selections from grid view have remembered and after rendering sorted view these records are getting selected again.

While in case of rec.set(), Instead of datachanged, 'update' event of Ext.data.store is getting fired. But there is no implementation related to select old records as same as headerclick on 'update' event.

So you have to implemet selection of records on after rec.set().

Here is discussion about similar issue.

Upvotes: 0

Related Questions