0

Here are two different tables @Oleg made:

On the first one, when clicking a single cell - the entire row is picked.

On the second one, only the clicked cell is picked.

This is being controlled with cellEdit: true.

I'd like to have a logic that will set cellEdit to false, but only for certain rows (under some condition, which for simplicity let's say this will happen when a cell's value is under 100).

How can this be achieved?

Community
  • 1
  • 1
OfirD
  • 9,442
  • 5
  • 47
  • 90
  • Your question isn't clear enough because you use reference the demo, which use **cell editing** mode, but you write about some rules for rows, which more corresponds **inline editing** mode. One can disable some **cells** from editing (in cell editing mode) by adding `"not-editable-cell"` class to the coresponding cells (using `cellattr`). One can disable editing of some **rows** (in inline editing mode) by adding `"not-editable-row"` class to the corresponding rows (using `rowattr`). What exactly you want to use cell editing or inline editing? – Oleg Feb 09 '17 at 22:24
  • @Oleg, thanks. Well, I have a followup issue: I experienced with [this](http://www.ok-soft-gmbh.com/jqGrid/CustomFormAndInlineEdit.htm) example grid. When selecting some row and changing the value on the "Category" column, and then selecting a different row, the picked value isn't saved, and is restored to its initial value. Can you give me an example where the value is actually updated and not restored? – OfirD Feb 12 '17 at 09:14
  • @Oleg, I'd like to do what you offered [here](http://stackoverflow.com/a/9974305/3002584) on the third bulletpoint: "You can implement saving of current editing row inside of onSelectRow or some other callback." – OfirD Feb 12 '17 at 09:32
  • Sorry, but I can't follow you. [The demo](http://www.ok-soft-gmbh.com/jqGrid/CustomFormAndInlineEdit.htm), which you reference, is from [the old answer](http://stackoverflow.com/a/4308172/315935), which is more as 6 years old. It uses `grid.jqGrid('editRow', id, **true**, null, null, 'clientArray');`, with `true` as the second parameter of `editRow`. It means that one need to press Enter to confirm saving. Clicking of another row without confirmation, calls `restoreRow` to discard the changes – Oleg Feb 12 '17 at 12:43
  • Please answer on the following questions: 1) Which version of jqGrid you use (can use) and from which fork of jqGrid ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7). 2) Which one editing mode you want to use: cell editing or inline editing? 3) Could you modify the text of your question oriented on either cell editing or inline editing mode? – Oleg Feb 12 '17 at 12:48
  • Right. I don't want to hit the Enter. I want to save the edited row when selecting another row. I just couldn't make that happen, so if there's an existing example, it would be nice. Answering your questions: I can use free jqGrid, need to use inline editing. – OfirD Feb 12 '17 at 12:49
  • Could you answer on my previous question? If you use inline editing for example then you can just replace `restoreRow` to `saveRow`, but I can't answer more till I don't know with which version and fork of jqGrid you work. – Oleg Feb 12 '17 at 12:51
  • Inline editing can be used in at least 3 ways: 1) `formatter: "actions"`, which creates editing buttons in every row, 2) `inlineNav`, which creates editing buttons in navigator bar near to the pager buttons, 3) explicit calls of `editRow`, `saveRow` or `restoreRow` inside of some callbacks (`beforeSelectRow`, `onSelectRow`, `ondblClickRow`). The first two ways are standard ways, which are intuitive for every user. One still can implement any custom behavior using the 3-d way. You original question was about **selective** editing of some rows. You want prevent editing of some rows. Isn't so? – Oleg Feb 12 '17 at 12:59

1 Answers1

0

To allow to edit data in some column one have to specify editable property in the column. Free jqGrid allows to use callback function as the value of editable property. The callback should return boolean value, which informs jqGrid, whether the cell is editable or not. The wiki article describes the feature more detailed. For example, the following callback in some column colModel allows editing of the cells only if the value in amount column is less as 100:

editable: function (options) {
    var item = $(this).jqGrid("getLocalRow", options.rowid);
    if (item.amount < 100) {
        return false;
    }
    return true;
}
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks! Please refer to [this](http://stackoverflow.com/questions/42214322/jqgrid-make-the-select-drop-down-disappear) follow-up question. – OfirD Feb 13 '17 at 22:00