Andrus
Andrus

Reputation: 27931

How to show image in jqgrid in edit mode

jqGrid contains image column defined using colmodel below. image id is passed in cell value from server in json. grid shows images properly if not in edit modes.

Inline and form edit mode show wrong image since editoptions src property contains fixed id 1

How to show image from editable row id in edit mode ? How to pass cell value to editoptions src property like in formatter function?

name:"Image",
edittype:"image",
editoptions:{ src: "GetImage?id=1"},
formatter:function(cell,options,row) {
     return "<img src='GetImage?id=" +  cell + "'/>"
  }

Upvotes: 0

Views: 7668

Answers (1)

Oleg
Oleg

Reputation: 221997

I can suggest you to change the value of the src property of the editoptions immediately before staring editing. Look at the answer for details. In case of form editing you can use beforeInitData to modify src:

beforeInitData: function () {
    var cm = grid.jqGrid('getColProp', 'flag'),
        selRowId = grid.jqGrid('getGridParam', 'selrow');
    cm.editoptions.src = 'http://www.ok-soft-gmbh.com/img/flag_' + selRowId + '.gif';
}

So you will receive the edit form like

enter image description here

for the grid

enter image description here

See the corresponding demo here.

Upvotes: 1

Related Questions