bfl*_*ow1 6 c# asp.net jquery-plugins jqgrid
我使用EF4和ASP.NET Web窗体的开源jqGrid插件.我需要根据DB中的列值在可内联编辑的网格行中设置输入元素.例如,第一行可以包含DDL,第二行可以包含复选框等.
我正在尝试使用custom_element和实现这一点custom_values,如下所示:
$("#grid1").jqGrid({
url: 'Default.aspx/getGridData',
datatype: 'json',
...
colModel: [
...
//contains the input type ('select', etc.)
{ name: 'InputType', hidden:true },
...
//may contain a string of select options ('<option>Option1</option>'...)
{
name: 'Input',
editable:true,
edittype:'custom',
editoptions:{
custom_element: /* want cell value from InputType column here */ ,
custom_value: /* want cell value from Input column here */
}
},
...
]
});
Run Code Online (Sandbox Code Playgroud)
该jqGrid的文档说,我可以调用自定义函数来设置custom_element和custom_values,但我不知道怎样才能捕捉的列值,并将其传递到我的自定义功能.
为了设置custom_values,我确实注意到Oleg使用该list:参数的很好的解决方案,但这似乎涉及额外的Ajax调用.我想避免这种情况,因为我已经从网格的初始Ajax调用中获得了所需的所有数据.
总之,我需要在内联编辑模式下执行以下操作:
我也愿意跳过使用custom_element和custom_values,但是我仍然面临着动态设置edittype和editoptions:{value:}参数的相同问题.
关于如何做到这一点的任何想法?我应该采取不同的方法吗?
更新:感谢您帮助我的努力.根据请求,这是我的JSON响应的缩写示例:
{"d":[
{"Input":null,"InputType":"select"},
{"Input":"From downtown, proceed west on Interstate 70.", "InputType":"text"}
]}
Run Code Online (Sandbox Code Playgroud)
有了这些数据,我想在一行中显示一个空选择,在下一行显示一个填充的文本字段.两者都可以内联编辑.
解决方案:我已经回到这个问题,以便找到一个不涉及使用custom_element和的解决方案custom_values.这是我的解决方案(基于下面接受的答案)改变edittype和editoptions:
loadComplete: function () {
var rowIds = $("#grid1").jqGrid('getDataIDs');
$.each(rowIds, function (i, row) {
var rowData = $("#grid1").getRowData(row);
if (rowData.InputType == 'select') {
$("#grid1").jqGrid('restoreRow', row);
var cm = $("#grid1").jqGrid('getColProp', 'Input');
cm.edittype = 'select';
cm.editoptions = { value: "1:A; 2:B; 3:C" };
$("#grid1").jqGrid('editRow', row);
cm.edittype = 'text';
cm.editoptions = null;
}
});
}
Run Code Online (Sandbox Code Playgroud)
Nota Bene:对我来说一件重要的事情就是记得在打电话之后editoptions回过头来.另外,正如Oleg在评论中提到的那样,避免使用自定义元素允许我实现datepicker输入而不会有额外的麻烦.这对我的应用来说很重要,所以我最终接受了Oleg的回答,但我仍然赞同Walter的回答.如果这是不好的形式,我真诚地道歉.我只想奖励最适合我的解决方案.nulleditrow
| 归档时间: |
|
| 查看次数: |
14689 次 |
| 最近记录: |