PDA

View Full Version : Disabling editing in a GridEditor



CableDawg
1 May 2007, 7:42 AM
Is there an easy way to disable the editing of a Grid built with the GridEditor class?

I would like to add a button to toggle the editability of a Grid and was wondering if there was an easy way to do that. I think you can disable an individual field, but I didn't see any reference to the Grid as a whole.

mystix
1 May 2007, 8:12 AM
listen to the grid's beforeedit event.

[here's some working code, tested on build 1.0.1a]
stick this after the grid.render() call in the examples/grid/edit-grid.js file:
var editFlag = false;
grid.on('beforeedit', function(e) {
e.cancel = editFlag; // setting e.cancel to true will disable editing
}, this);
Ext.fly('toggleEdit').on('click', function() {
editFlag = !editFlag;
}, this);


and this after the grid-panel <div> in examples/grid/edit-grid.html:
<input type='button' id='toggleEdit' value='Toggle Edit'/>