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

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Aditya K
  • 159
  • 1
  • 4
  • 13

2 Answers2

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • 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..? – Aditya K Oct 13 '11 at 09:55
  • @stacktrace: `editRow` method tests which columns are editable **at the moment**. It create `` or ` – Oleg Oct 13 '11 at 11:10
  • Hi Oleg, Will you please help me on this? http://stackoverflow.com/questions/7752611/how-to-avoid-scroll-to-top-when-i-click-on-any-non-editable-cell-in-jqgrid-subgr Thanks – Aditya K Oct 14 '11 at 12:26
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 :)

Community
  • 1
  • 1
DMv2
  • 198
  • 1
  • 12
  • Why you don't call `jQuery('#grid').jqGrid('editRow', rowId, {});` at the end, after you set `cm.editable = true`? – OfirD Jan 11 '18 at 08:55
  • 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. – DMv2 Jan 12 '18 at 10:46