问题: 如何使我的“editable:true”列正确排序?
以下链接似乎提供了一个“onclick”处理程序函数,以允许对可编辑的列进行排序。(https://stackoverflow.com/a/9290716/652078)
但是,即使使用它,当我单击该列时也会收到以下错误:
'handler' is null or not an object
单击列时的消息
下面,我提供了从上述链接中借用的列定义和“单击”处理程序代码。
- 这个解决方案有什么过时的东西会阻止它工作吗?
- 或者,我的列定义是否会阻止这样的“onclick”处理程序工作?
谢谢你的帮助!
这是列定义:
{
name: 'recType',
label: 'recType',
index: 'recType',
width: 100,
fixed: true,
keys: true,
editable: true,
edittype: "select",
editoptions: {value: rectypelist},
stype: 'select',
formatter: 'select'
},
点击事件函数(上面链接中描述的技术)...
$(".ui-jqgrid-htable th").click(function() //.on('click', 'th', function(e) //
{
var $grid = contentB1Grid;
$.each($grid[0].grid.headers, function () {
var $th = $(this.el), i, l, clickHandler, clickHandlers = [],
currentHandlers = $._data($th[0], "events"), //$th.data('events'),
clickBinding = currentHandlers.click;
if ($.isArray(clickBinding)) {
for (i = 0, l = clickBinding.length; i < l; i++) {
clickHandler = clickBinding[i].handler;
clickHandlers.push(clickHandler);
$th.unbind('click', clickHandler);
}
}
$th.click(function () {
var p = $grid[0].p, savedRow = p.savedRow, j, len = savedRow.length;
if (len > 0) {
// there are rows in cell editing or inline editing
if (p.cellEdit) {
// savedRow has the form {id:iRow, ic:iCol, name:nm, v:value}
// we can call restoreCell or saveCell
//$grid.jqGrid("restoreCell", savedRow[0].id, savedRow[0].ic);
$grid.jqGrid("saveCell", savedRow[0].id, savedRow[0].ic);
} else {
// inline editing
for (j = len - 1; j >= 0; j--) {
// call restoreRow or saveRow
//$grid.jqGrid("restoreRow", savedRow[j].id);
$grid.jqGrid("saveRow", savedRow[j].id);
}
}
}
});
l = clickHandlers.length;
if (l > 0) {
for (i = 0; i < l; i++) {
$th.bind('click', clickHandlers[i]);
}
}
});
});