我知道editype="select"
选项,但是,为了查看选择,用户必须启动编辑。
相反,我只想让下拉列表默认显示在单元格中,而无需用户开始编辑。
我尝试过的: html是从jQGrid AJAX调用的PHP函数返回的:
<cell><select><option>Test</option></select></cell>
我将列的格式化程序设置为“select”
我如何做到这一点?
答案 0 :(得分:3)
是的,你可以在列模型中使用custom fortmatter
{
name: 'MyCol', index: 'MyCol', formatter: customSelectboxRenderer
}
然后
function customSelectboxRenderer(cellValue, opts, rowObject){
return "<select>...</select>";//options can be prepared from some local array
}
答案 1 :(得分:1)
假设你的意思是
<cell><select><option>Test</option></select></cell>
是针对相关单元格返回的响应。
我认为您只需删除单元格标记并从您自己的自定义格式化程序返回该标记
之类的东西function customFormatter(cellValue, opts, rowObject){
// Assuming that cellValue is <cell><select><option>Test</option></select></cell>
return cellValue.replace(blah);
}
或者,如果您可以更改从服务器返回的单元格的值,那么我会尝试查看是否在没有格式化程序的情况下工作,如果它不是您想要创建返回单元格值的自定义格式化程序。
function customFormatter(cellValue, opts, rowObject){
// Assuming that cellValue is <select><option>Test</option></select>
return cellValue;
}
如果我的假设不正确,请澄清。
答案 2 :(得分:0)
我做了我生命中最狡猾的事情:我改变了'&lt;'字符到<
并更改了'&gt;'服务器端数据上的>
字符
这样,当jqgrid接收时,数据不会被剥离标签
然后我制作了一个自定义格式化程序,用实际字符替换html代码,使数据正确显示。
formatter: function(cellvalue, options, rowObject){ return cellvalue.replace("<","<").replace(">",">"); }
轰!完成交易。