PDA

View Full Version : Deselect a grid cell when adding a new row (remove blue background)



torsten.t
4 Jan 2013, 1:19 AM
When adding a new row the former edited cell is still marked active.

Steps to reproduce:
I edit the first cell in row number 3 of a grid panel.
Now I add a new record and start editing the first cell of this record. This works

But the former edited cell in row 3 gets the blue background (x-grid-cell-selected).
How can I remove the blue background from the cell in row 3 ?
As the first cell of the new row is edited the cell in row 3 should not be marked active.

I have a Cellediting Model and am trying to deselect the marked cell in the handler of the Add-Button


plugins: [cellEditing],
dockedItems: [{
xtype: 'toolbar',
items: [{
iconCls: 'icon-add',
text: 'Add',
itemId: 'bt_add',
handler: function () {
var grid = this.up('panel');
grid.getSelectionModel().deselectAll(); // not working, now cell in row 2 is marked ???
grid.getSelectionModel().getLastSelected().deselect; // not working, cell in row 3 still marked
var rec = new GridModel({
});
rec.setDirty();
grid.getStore().insert(0, rec);
//grid.getStore().first().setActive();
grid.getView().select(rec); // not working, cell in row 3 still marked
cellEditing.startEdit(0, 0);
grid.down('#bt_add').disable();
}

Jad
4 Jan 2013, 1:36 AM
try to refresh the view

me.getView().refresh();

torsten.t
4 Jan 2013, 2:15 AM
Thanks Jad, Excellent.

It is a good idea to put the refresh at the end. The following is working


plugins: [cellEditing],
dockedItems: [{
xtype: 'toolbar',
items: [{
iconCls: 'icon-add',
text: 'Add',
itemId: 'bt_add',
handler: function () {
var grid = this.up('panel');
var rec = new GridModel({
});
rec.setDirty();
grid.getStore().insert(0, rec);
grid.getView().select(rec);
cellEditing.startEdit(0, 0);
grid.getView().refresh(); // This line is the important one. Thanks Jad
grid.down('#bt_add').disable();
}

Jad
4 Jan 2013, 2:20 AM
you're welcome