0

How can I enable one column to be editable only if it's in a new row? This column must be read-only in existing rows when in edit mode.

The editable attribute works for new and existing rows.

juliano.net
  • 7,982
  • 13
  • 70
  • 164

1 Answers1

0

What is the type of editing are you using? Form editing or inline editing?

If it is form editing you can use beforeShowForm event to hide the non-editable fields from the edit form.

beforeShowForm:function(formid)
{
 id="#tr_"+columnName(as given in column model);
 $(id, form).hide();
}

you need to make the hidden fields visible in add form again by using the same event

beforeShowForm:function(formid)
 {
  id="#tr_"+columnName(as given in column model);
  $(id, form).show();
 }

If it is inline editing before calling editRow, set editable flag to false

$('#gridId').jqGrid('setColProp',columnName,{editable: false}); 

and after editRow was over reset the editable flag to true to make editable for newly added rows

$('#gridId').jqGrid('setColProp',columnName,{editable: true}); 

Hope it helps....

Vinod Kumar
  • 75
  • 10
  • I'm using inline editing, however, the user can edit and add new rows at the same time, then I can't disable the column editing for the entire grid. – juliano.net Dec 30 '13 at 11:24
  • Don't set editable flag in column model. Before Calling addRow method set $('#gridId').jqGrid('setColProp',columnName,{editable: true}); and before calling editRow method set $('#gridId').jqGrid('setColProp',columnName,{editable: false}); – Vinod Kumar Dec 31 '13 at 11:22
  • I do not save every row on every change, the user can change several (or all) and add a bunch of rows before submitting them. If I use setColProp, all of the rows will have that column editable or read only on these events. – juliano.net Dec 31 '13 at 17:58
  • So,is your problem to distinguish the add and edit operations.You can do it by adding a new element to rowdata. rowdata = ('#gridid').jqGrid ('getRowData',rowid); If it is add operation set rowdata.opflag = 'add'; or else set it to 'edit'. Read this flag before sending row into edit mode(onselectrow or ondoubleclick) and according to that flag set editable property of the corresponding columns either true or false. – Vinod Kumar Jan 06 '14 at 10:57