根据网格另一列中的id值在Jqgrid的一列中获取图像
我有一个JQGrid,有4列,如下所示根据网格另一列中的id值在Jqgrid的一列中获取图像,jqgrid,get,rowid,identify,Jqgrid,Get,Rowid,Identify,我有一个JQGrid,有4列,如下所示 <script type="text/javascript"> $(function(){ jQuery("#toolbar").jqGrid({ url:'<%=request.getContextPath()%>/TestServlet?q=1&action=fetchData', datatype: "xml",
<script type="text/javascript">
$(function(){
jQuery("#toolbar").jqGrid({
url:'<%=request.getContextPath()%>/TestServlet?q=1&action=fetchData',
datatype: "xml",
mtype: 'POST',
height: '100%',
width: '100%',
colNames:['LocationImage','City','State','LocationID'],
colModel:[
{name:'LocationImage',index:'LocationImage',align: 'center', formatter: imageFormatter},
{name:'City',index:'City', width:200,fixed:true,sortable:true,align:'center',editable:true, editoptions:{readonly:false,size:500}},
{name:'State',index:'State', width:200,fixed:true,sortable:true,align:'center',editable:true, editoptions:{readonly:false,size:50}},
{name:'LocationID',index:'LocationID',width:60,align:'center',hidden:true,editable:false, editoptions:{readonly:true,size:30}
],
paging: true,
rowNum:16,
rowTotal:2000,
rownumbers: true,
rownumWidth: 25,
rowList:[16,32,48],
viewrecords: true,
loadonce: true,
gridview: true,
pager: $("#ptoolbar"),
sortname: 'Name',
sortorder: "asc",
caption: "Test Grid"
})
jQuery("#toolbar").jqGrid('navGrid','#ptoolbar',{del:false,add:false,edit:false});
jQuery("#toolbar").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
});
function imageFormatter(el, cval, opts) {
var num = '2';
return ("<center><img src='../gd/images/" + num+".png' height='180px' width='180px' /></center>")
}
$(函数(){
jQuery(“工具栏”).jqGrid({
url:“/TestServlet?q=1&action=fetchData”,
数据类型:“xml”,
mtype:“POST”,
高度:“100%”,
宽度:“100%”,
colNames:['LocationImage'、'City'、'State'、'LocationID'],
colModel:[
{名称:'LocationImage',索引:'LocationImage',对齐:'center',格式化程序:imageFormatter},
{name:'City',index:'City',width:200,fixed:true,sortable:true,align:'center',editable:true,editoptions:{readonly:false,size:500},
{name:'State',index:'State',width:200,fixed:true,sortable:true,align:'center',editable:true,editoptions:{readonly:false,size:50},
{名称:'LocationID',索引:'LocationID',宽度:60,对齐:'center',隐藏:true,可编辑:false,编辑选项:{只读:true,大小:30}
],
是的,
rowNum:16,
总数:2000,
行数:对,
行宽:25,
行列表:[16,32,48],
viewrecords:是的,
有一次:是的,
gridview:没错,
传呼机:$(“#ptoolbar”),
sortname:'名称',
分拣员:“asc”,
标题:“测试网格”
})
jQuery(“#toolbar”).jqGrid('navGrid','#ptoolbar',{del:false,add:false,edit:false});
jQuery(“#toolbar”).jqGrid('filterToolbar',{stringResult:true,SearchOneNoter:false});
});
函数图像格式化程序(el、cval、opts){
var num='2';
返回(“”)
}
这里我将num硬编码为“2”,因此在第一列即LocationImage中显示2.png,我需要的是num的值应该来自第四列即LocationID(注意它是一个隐藏列)
请让我知道怎么做
谢谢,
Deepna您应该将
imageFormatter
功能更改为如下:
function imageFormatter(cellvalue, options, rowObject){
var num = $("#" + options.rowId).find("td[aria-describedby='toolbar_LocationID']").text();
return "<center><img src='../gd/images/" + num + ".png' height='180px' width='180px' /></center>";
}
函数imageFormatter(单元格值、选项、行对象){
var num=$(“#”+options.rowId).find(“td[aria descripbedby='toolbar\u LocationID']”)text();
返回“”;
}
好的,我不太确定,我现在不能测试。但下面是你可以做的
从options参数中,您可以获取行id,选中,然后使用getCell或getGridParam获取具有该行id的位置id。您可以使用此值设置图像
如果这对自定义格式化程序不起作用,可以在JqGrid的gridComplete属性中使用setCol方法
现在,这只适用于一个id。如果要为所有行设置映像,请在变量中使用getDataIDs方法获取行id,然后使用for循环并使用setCol
我希望这有帮助我能够通过以下方式解决此问题
DeepnaDavid-我尝试了这段代码,但num返回null-它没有从LocationID列中选取值。Piyush-感谢您将我指向格式化程序链接,但是我找到了解决此问题的另一种方法…将解释,作为回答,Posterhaps可以链接到该帖子??如何接受回复?我可以看到反馈选项不知何故,我认为这个网站的用户界面并不友好……)如果你发现答案很好,那么点击勾号标记答案。