问题描述
我知道使用日期选择器进行单元格编辑是可能的,因为在此处和此处.但是,当我单击该单元格时,没有显示日期选择器.以下是相关列的colModel条目.我有可用的datepicker UI.
I know that cell editing with datepicker is possible because of references here and here. However, when I click on the cell, no datepicker shows up. Below is the colModel entry for the column in question. I have datepicker UI available.
在其他示例中,dataInit不被引号引起来.它在我的代码中,因为整个colModel是由PHP在AJAX请求期间动态创建的.我将其构建为数组,然后对其进行json_encode传递回jqGrid. PHP的json_encode创建有效的JSON,因此所有键均引用为字符串.我是否必须删除引号才能使jqGrid正常工作?如果可以,怎么办?
In the other examples, dataInit is not surrounded by quotes. It is in my code because the whole colModel is dynamically created by PHP during an AJAX request. I build it as an array, then json_encode it to be passed back to jqGrid. PHP's json_encode creates valid JSON, so all keys are quoted as strings. Must I remove the quotes in order for jqGrid to work properly? If so, how?
日期列的colModel条目:
The colModel entry for a date column:
{
"editable":true,
"name":"date",
"index":"date",
"sorttype":"date",
"editrules":{"date":true},
"editoptions":{
"dataInit":"function(elem){
setTimeout(function(){
$(elem).datepicker();
},100);
}"
}
}
这是ajax请求的结构:
Here is the structure of 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',
});
}
});
});
另外,我正在使用jqGrid 4.0.0
Also, I'm using jqGrid 4.0.0
推荐答案
我在通过PHP的json_encode传递函数时遇到了同样的问题,这是不可能的,但是如果您使用Zend Framework,则可以使用Zend_Json_Expr('function ... ')使用函数,然后使用Zend_Json :: encode($ var)进行编码.
I had the same problem with passing a function with PHP's json_encode, which is impossible but if you are using Zend Framework you could use Zend_Json_Expr('function ...') to use a function and then encode with Zend_Json::encode($var).
但这仍然不能解决问题,因为如果稍后通过AJAX插入事件,则不会触发该事件.
Still this won't solve the problem cause the event will not be fired if you insert it later thru AJAX.
您可以查看 Pike_Grid 看看它是如何完成的在那里.
You could have a look to Pike_Grid to see how it's done there.
这篇关于实现jqgrid单元格编辑datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!