如何在 JQGard 中单击图像时显示大图像

how to show large image if clicking in image in jqgrid

本文关键字:图像 显示 单击 JQGard      更新时间:2023-09-26

jqgrid图像列使用下面的colmodel定义。在表单编辑模式下,如果鼠标悬停在图像上,光标将变为手,但单击图像将被忽略。

如果在图像中单击,如何在分离窗口中显示大图像?大图像由 url 'http://localhost/Grid/GetImage?id=' + options.rowId(不带大小参数)引用。

{"label":"Logo","name":"_image_Logo","edittype":"image",
    "editoptions":{"src":""},
    "editable":true,
    "formatter":function(cell,options,row) {
      return '<img src="http://localhost/Grid/GetImage?size=150&id=' +
               options.rowId +'" />';
} ,
"search":false,"title":false,"width":150},    
{"edittype":"file","label":"","name":"Logo","search":false,
"title":false,"width":150,"hidden":true,
"editrules":{"edithidden":true},"editable":true}

更新

我尝试了奥列格和迈克尔的建议,使用下面的colmodel。我需要将行 ID 传递给图像控制器。在网格中单击图像工作正常,打开大图像。 options.rowId图像 ID 恢复。

在编辑表单中,不传递行 ID。如何在点击事件中传递options.rowId而不是e.target.id

{"name":"Image",
"edittype":"image",
  "editoptions":{
    "src":"",  
    "dataEvents":[{"type":"click","fn":function(e) {
      window.open('GetImage?id=' + e.target.id, e.target.id )
  }
}]},
  "editable":true,
   "formatter":function(cell,options,row) {
    return '<a href="GetImage?id=' + options.rowId+'"><img src="GetImage?size=54&id=' + 
         options.rowId +'" /></a>';
} 
,"search":false,"title":false,"width":54},
例如,

您可以使用onCellSelectbeforeSelectRow来捕获图像上的click并实现所需的任何自定义操作(例如显示大图像)。

如果只需要在编辑模式下对图像click实现某些操作dataEvents则可以使用编辑选项的属性。

如果您将格式化程序返回更改为类似 <a href="LARGE_IMAGE_URL"><img src="IMAGE_URL" /></a> 的内容怎么办?这是你想要的吗?