How to disable editing for some cells in row editing of JQGrid?
Asked Answered
C

2

5

When I click on any row of my Grid, All editable columns become editable.

I want some of the columns to be editable on each row separately.

                 Column 1,   Column 2,     Column 3             
ROW Number 1 - editable,     non-editable, non-editable  
ROW Number 2 - non-editable, editable,     non-editable    
ROW Number 3 - editable,     non-editable, non-editable  

Thanks in Advance

Cursive answered 11/10, 2011 at 9:1 Comment(0)
E
12

If you use inline editing mode and want to decide dynamically which cells of the row will be editable for example based on the contain of the cells you can do this in the way which I described here. You can do this with another method also:

$(this).jqGrid('setColProp', 'YouColumnName', {editable:false});

So you should just set editable to false or true before calling of editRow method. In the way you can implement any logic which you want.

UPDATE: Free jqGrid allows to define editable as callback function. See the wiki article. It allows to make the column editable in some rows and holding non-editable for other rows.

Emmerie answered 11/10, 2011 at 21:8 Comment(3)
Ok, So that I can check the value of a cell in a row. And then make it editable : false. So it becomes non editable for the selected row right..?Cursive
@stacktrace: editRow method tests which columns are editable at the moment. It create <input> or <select> controls to the cell editing only for the editable columns. So if you set column property of some column temporary to editable:false no control for editing will be created and the corresponding cell will be non-editable like you as want. Directly after the call of the editRow method you can change the setting back to any value which you want. In the way you would full solve the problem which you have.Emmerie
Hi Oleg, Will you please help me on this? #7753111 ThanksCursive
B
0

I had a similar requirement, just expanding on what Oleg already mentioned in his answer:

//get colModel properties
var cm = jQuery("#grid").jqGrid('getColProp','myColumn');

//some condition to enable or disable editing
cm.editable = false;

//always call editRow after changing editable property
jQuery('#grid').jqGrid('editRow', rowId, {});

//set default editable option
cm.editable = true;

Cheers :)

Bus answered 26/8, 2015 at 8:35 Comment(2)
Why you don't call jQuery('#grid').jqGrid('editRow', rowId, {}); at the end, after you set cm.editable = true?Grout
Because that will set the cell to editable again. Here what you are trying to do is make a particular cell conditionally non-editable but rest of the columns stay editable. cm.editable = true; is to set col model back to editable whenever editRow is called again.Bus

© 2022 - 2024 — McMap. All rights reserved.