QUESTION: How do I enable my "editable:true" column to sort properly?
The following link seemed to provide an "onclick" handler function to allow editable columns to be sorted. (https://stackoverflow.com/a/9290716/652078)
But, even when using it, I receive the following error when I click on the column:
'handler' is null or not an object
message when I click on the column
Below, I've provided the column definition and the "click" handler code that I borrowed from the above link.
-Is there anything out-of-date regarding this solution that would prevent it from working?
-Or, does my column definition preclude such a "onclick" handler from working?
Thanks for any help!
Here is the column definition:
{
name: 'recType',
label: 'recType',
index: 'recType',
width: 100,
fixed: true,
keys: true,
editable: true,
edittype: "select",
editoptions: {value: rectypelist},
stype: 'select',
formatter: 'select'
},
The click event function (technique described in the above link)...
$(".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]);
}
}
});
});