我使用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處理程序中可靠地獲取「調用」表的句柄?