I had a question before about implementing datepicker with jqgrid. I think that question was too specific. I would like to know, has anyone been able to implement a datepicker with a dynamic jqGrid? The colModel, colNames, and in my case, data are generated server-side via an ajax request, then displayed locally. On the server, in PHP, I create an array with the colModel structure, then JSON encode it before sending it back to client. Valid JSON puts quotes around the keys, but according to examples here, here, and (importantly) here, I'm not supposed to do that.
I tried to use regex to remove the quotes, but that just results in a javascript error because it can no longer parse the now-invalid JSON.
Is datepicker with dynamic colModel possible?
Here is the AJAX request:
$(document).ready(function(){
$.ajax({
type: "GET",
datatype: "json",
success: function(result){
try{
//alert(result);
result = jQuery.parseJSON(result);
}catch(err){
alert("error in success json " + err);
return;
}
var colN = result.colNames;
var colM = result.colModelList;
var colD = result.colDataList;
grid.jqGrid({
datatype: 'local',
colNames:colN, //column names
colModel:colM, //column options
data:colD, //table data
editurl: 'clientArray',//changes are not sent to server
cellEdit: true,
cellsubmit: 'clientArray',
});
}
});
});
and an example colModel:
{
"editable":true,
"name":"date",
"index":"date",
"sorttype":"date",
"editrules":{"date":true},
"editoptions":{"dataInit":"initDateEdit"}
}