The problem is clear. JSON don't support functions as a type. What you easy can do is the following: 1) you fill strings as the value of dataInit
on the server side. 2) you "pre-process" the column model and change illegal string values of dataInit
to the reference to the corresponding function. You can "pre-process" the column model before creating of the grid or after creating inside of beforeProcessing
callback or even later somewhere before starting of editing. Because dataInit
will be used only during editing you have to fix dataInit
at any time before the editing will be started.
To change colModel
you can either use setColProp
method or you can get the reference of internal colModel
array by var colModel = $("#gridid").jqGrid("getGridParam", "colModel");
and then do any required modification of some columns. The code will look about as below:
function numericonly(elem) {
...
}
...
var colModel = $("#gridid").jqGrid("getGridParam", "colModel"), i, cm;
for (i = 0; i < colModel.length; i++) {
cm = colModel[i];
if (cm.editoptions != null && typeof cm.editoptions.dataInit === "string") {
switch (cm.editoptions.dataInit) {
case "numericonly":
// function numericonly is visible here and can be used
cm.editoptions.dataInit = numericonly;
break;
....
default:
delete cm.editoptions.dataInit; // delete wrong value
break;
}
}
}
The old answer contains description of the same idea for the case of custom formatters.