PDA

View Full Version : Disable Editability on Specific rows in EditorGrid



MD
24 Mar 2007, 10:15 PM
I'm having a bit of trouble determining if this is in fact possible to do. An example would be that I have data coming in to populate the grid, and

As part of the data that populates my EditorGrid, I have flag values to denote whether a row is 'locked' or 'unlocked' (0/1). As part of the renderer for the row's columns/cells, I would test that 0/1 (true/false), and in turn either allow editability as normal, or disable it for that cell. As normal, when the data is first populates the grid, it would pass through the renderer and any flagged as locked would be disabled right off the bat.

I've been through many posts in the forum seeking out an answer, but have to come across the right way to implement, or whether in fact it's even possible. My failed attempt at it so far was as such:



function renderBlah(value, p, r){
if (r.data['locked'] == "1")
p.attr = 'ext:editable="false" ext:qtip="Tooltip Text" ext:qtitle="Tooltip Title"';
return value;
}


The ext:editable="false" was more of a guess based on the actual working attribs for qtip/qtitle :oops:

JeffHowden
24 Mar 2007, 11:00 PM
Add a listener to the beforeedit event of the grid.

http://www.yui-ext.com/deploy/ext-1.0-alpha3/docs/index.html#output/Ext.grid.EditorGrid.html

In that listener, check for the 0/1 value and return false if it's not to be editable.

MD
25 Mar 2007, 11:31 AM
Thanks for the response, Jeff.

I'm in the right direction now, but unclear as to how to pull out the info I need in the handler func -- I've seen mixed examples of the old pre-1.0 alpha methods and only the properties for 1.0 alpha.

I've seperately tried both of the following without success:



grid.addListener('beforeedit', function(grid, record, field, value, row, column, cancel){ alert('MARKER HIT'); alert(grid+', '+record+', '+field+', '+value+', '+row+', '+column+', '+cancel); });

//Trying both ways to fetch the event obj's properties
grid.addListener('beforeedit', function(e){ alert('MARKER HIT'); alert(e+', '+e['grid']+', '+e.grid+', '+e.record+', '+e.record['lastPost']); });

JeffHowden
25 Mar 2007, 11:41 AM
grid.on('beforeedit', function(e) {
// do stuff here
});

Use console.log() to find the contents of "e".

MD
25 Mar 2007, 12:25 PM
ah ha, .on is an alias for .addListener ;) Works great now, thanks so much, Jeff.

Sorry, one other thing I meant to ask -- "cancel - Set this to true to cancel the edit or return false from your handler." -- Where would I set that? Within the handler function? e.cancel = true; or outside? And what's the advantage of using cancel over just simply doing a return false;?

JeffHowden
25 Mar 2007, 12:44 PM
Yeah, if "e" is your event argument, you should be able to just set e.cancel = true.