我使用jqGrid在页面上构建自定义内联条目小部件。在jqjGrid设置的相关部分是:jqGrid自定义输入元素需要父表处理
colModel:[ {
// Other columns removed.
{name:'ship',index:'ship', width:90, editable: true, sortable: false,
edittype: "custom",
editoptions:{ custom_element: customElement,
custom_value: customValue} }
],
我的回调函数是:
function customElement(value, options) {
var a = $("<input>").attr({
type: 'text',
size: 2,
value: value,
style: 'float: left'
}).add(
$("<span>").attr({
style: 'float: left; margin-top: 2px;',
'class': 'ui-icon ui-icon-search'
}).click(function() {
// My custom function here.
})
).appendTo($("<div>"));
return a;
}
这一切都正常工作。
但是,我正在建立一个库来管理页面上的几个jqgrid表。我想使用相同的函数在几个这样的表上构建自定义元素。问题是这个特定的函数需要知道它正在处理哪个jQuery表。
我可以在customElement
开始通过哈克的方式获得表ID,并在关闭它传递给函数:
var fieldID = options.id;
var rowID = fieldID.replace(/_.*/, "");
var containingTable = $("#" + rowID + "_id").closest("table");
但这是假设列“ID”在当前的jqGrid存在,它是较早的(向左)列。我无法使用“发货”栏,因为它尚未创建。我不能假设表中有其他行也会有“发货”列。
我该如何在custom_element处理程序中可靠地获取“调用”表的句柄?