8

I have a jQGrid with a column that I only want to be editable when adding a new row.

I've seen examples of how to do this when edits and adds are both happening in a dialog but is there a way to do this with in-line editing?

I've tried using grid.setColProp() in beforeShowForm:, but this doesn't work ( the column remains read only and is not present in the add dialog).

Example of dialog based column enable/disable:
http://www.ok-soft-gmbh.com/jqGrid/CustomFormEdit.htm

Oleg
  • 220,925
  • 34
  • 403
  • 798
David
  • 83
  • 1
  • 1
  • 4

1 Answers1

18

Because you use the example from my old answers (this and this) I feel that I should answer also on your question.

In the old example all fields, which can be modified during Add or Edit dialogs, has property editable:true. The fields which should be shown only in the Add dialog will be made hidden inside of beforeShowForm event handle. In the same way we can temporary switch some fields to editable:false before call of the editRow method and reset back to the editable:true immediately after the call:

onSelectRow: function(id) {
    if (id && id !== lastSel) {
        grid.jqGrid('restoreRow',lastSel);
        var cm = grid.jqGrid('getColProp','Name');
        cm.editable = false;
        grid.jqGrid('editRow', id, true, null, null, 'clientArray');
        cm.editable = true;
        lastSel = id;
    }
}

You can see this live here.

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
  • Great! Have you any blog posts, publications or another stack answers on jQGrid? – Sergey Metlov Sep 21 '11 at 06:51
  • @DotNET Ninja: Currently I write only answers on stackoverflow and in the trirand forum. I hope I will find time next time and write a blog or articles or a book which describes how to work effectively with jqGrid. – Oleg Sep 21 '11 at 07:45
  • @Oleg: This seems to work if we want to make one column as not editable across all rows. Is there a way to make a particular column editable for some rows and not for other rows? I looked around and was not able to find anything close to what I am looking for. Thank you in advance. – RRK Apr 30 '13 at 00:31
  • @RRK: The *current value* of property `editable` will be used by `editRow`. So if you change *common* property `editable` before every call of `editRow` like I shown then you do can make non-editable selected rows only. – Oleg Apr 30 '13 at 05:00
  • @Oleg: Thank you. It is working now. I missed the part where you reset the editable property after editRow call. – RRK Apr 30 '13 at 17:31