【问题标题】:implement jqgrid cell edit datepicker实现jqgrid单元格编辑日期选择器
【发布时间】:2011-07-08 19:26:04
【问题描述】:

我知道使用日期选择器编辑单元格是可能的,因为引用 herehere。但是,当我单击单元格时,没有显示日期选择器。下面是相关列的 colModel 条目。我有可用的日期选择器 UI。

在其他示例中,dataInit 没有被引号包围。它在我的代码中,因为整个 colModel 是由 PHP 在 AJAX 请求期间动态创建的。我将它构建为一个数组,然后将它的 json_encode 传递回 jqGrid。 PHP 的 json_encode 创建有效的 JSON,因此所有键都被引用为字符串。我必须删除引号才能使 jqGrid 正常工作吗?如果有,怎么做?

日期列的 colModel 条目:

{
 "editable":true,
 "name":"date",
 "index":"date",
 "sorttype":"date",
 "editrules":{"date":true},
 "editoptions":{
   "dataInit":"function(elem){
       setTimeout(function(){
          $(elem).datepicker();
       },100);
    }"
 }
}

这里是ajax请求的结构:

$(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

【问题讨论】:

  • 奥列格回答here
  • 这似乎与上述问题重复(属性名称已更改,但问题相同:您无法传递 javascript code 通过 JSON,它用于数据。您必须沿着该路径的某处进行一些处理,才能将字符串化的数据恢复为代码。

标签: php jqgrid


【解决方案1】:

我在使用 PHP 的 json_encode 传递函数时遇到了同样的问题,这是不可能的,但如果您使用 Zend Framework,您可以使用 Zend_Json_Expr('function ...') 来使用函数,然后使用 Zend_Json::encode 进行编码($var)。

这仍然不能解决问题,因为如果您稍后通过 AJAX 插入该事件,则不会触发该事件。

您可以查看Pike_Grid 以了解它是如何完成的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2015-12-18
    • 2021-11-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多