0

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 + "'/>"
  }
Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

1

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thank you very much. How to make image really editable by allowing user to upload new image in add and edit? Can we use html5 file upload feature or jquery form plugin from dataProxy ? – Andrus Oct 01 '11 at 17:32
  • I posted question about real image editing in http://stackoverflow.com/questions/7614667/how-to-make-file-upload-plugin-to-behave-like-ajax-call – Andrus Oct 01 '11 at 17:40
  • saving row data changes row image in server also. However new image is not displayed in edit form and in grid. Image http request is not generated after save. Only pressing browser refresh button shown new image in grid. How to show new image immediately after row is updated ? – Andrus Oct 02 '11 at 20:46