PDA

View Full Version : How to disable/enable cell editing based on another variable (flag)



nikita.navale
10 Jan 2013, 6:38 AM
Hi,

I am working with RowEditor and trying to enable/disable the editable property dynamically. But as many different ways I try, it doesnt seem to work.

For eg: in following scenario, I want to enable the 'user' column based on the flag 'tempVar'


...
var tempVar = true;
var dataColumns = [
{id: 'key', header: 'Key', width: 90, xtype : 'pslgridcolumn', dataIndex: 'key'},
{id: 'value', header: 'Value', xtype : 'pslgridcolumn', width: 135, dataIndex: 'value', editor: { xtype: 'textfield', allowBlank: false }},
{id: 'user', header: 'User', xtype : 'pslgridcolumn', width: 50, dataIndex: 'user', editor: { xtype: 'textfield'}, editable: false},
{id: 'client', header: 'Client', xtype : 'pslgridcolumn', width: 40, dataIndex: 'client', editor: { xtype: 'textfield'}}];
...
.. var editor = new Ext.ux.grid.RowEditor({
saveText: 'Update',
});
..
function checkEditable(){
if(tempVar) {
var record = catValueGrid.getSelectionModel().getSelected();
var rowIndex = catValueGrid.store.indexOf(record);
var colIndex = catValueGrid.getColumnModel().getIndexById('user');
var v_editor = catValueGrid.getColumnModel().getCellEditor(colIndex,rowIndex);
v_editor.enable();
}
}




I am not sure, if what I am doing is applicable in this scenario.

Any help is appreciated.

Thanks

mitchellsimoens
13 Jan 2013, 9:27 AM
Have you tried listening for beforeedit and returning false to cancel edit?

nikita.navale
14 Jan 2013, 2:42 AM
Yes, I had found the work around using beforeedit. Though canceledit didnt help.
Following is the working code which I implemented.



beforeedit: function (roweditor, rowIndex) {
var data = roweditor.grid.store.getAt(rowIndex).data;
var cm = roweditor.grid.getColumnModel();

if (/*my condition check using 'data' variable*/) {
var c = cm.getColumnAt(4);
c.editor.disable();
c = cm.getColumnAt(5);
c.editor.disable();
} else {
var c = cm.getColumnAt(4);
c.editor.enable();
c = cm.getColumnAt(5);
c.editor.enable();
}
}


Hope it helps others.

Thanks