【问题标题】:jqgrid - use datepicker with dynamic colModeljqgrid - 使用带有动态 colModel 的 datepicker
【发布时间】:2011-07-14 14:40:39
【问题描述】:

我有一个关于使用 jqgrid 实现 datepicker 的问题 before。我认为这个问题太具体了。我想知道,有没有人能够使用动态 jqGrid 实现日期选择器? colModel、colNames,在我的例子中,数据是通过 ajax 请求在服务器端生成的,然后在本地显示。在服务器上,在 PHP 中,我使用 colModel 结构创建一个数组,然后对其进行 JSON 编码,然后再将其发送回客户端。有效的 JSON 在键周围加上引号,但根据示例 herehere 和(重要的是)here,我不应该这样做。

我尝试使用正则表达式删除引号,但这只会导致 javascript 错误,因为它无法再解析现在无效的 JSON。

可以使用动态 colModel 的日期选择器吗?

这里是 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',
    });
   }
  });
});

还有一个示例 colModel:

{
 "editable":true,
 "name":"date",
 "index":"date",
 "sorttype":"date",
 "editrules":{"date":true},
 "editoptions":{"dataInit":"initDateEdit"}
}

【问题讨论】:

    标签: php ajax jqgrid


    【解决方案1】:

    查看this 的答案。它应该可以解决您的问题。

    【讨论】:

    • 还是没有运气。我正在使用var functionsMapping = { "initDateEdit": function(elem) {setTimeout(function() {$(elem).datepicker();},100);} };for (i=0;i<colM.length;i++) { cm = colM[i]; if (cm.editoptions.hasOwnProperty("dataInit") && functionsMapping.hasOwnProperty(cm.editoptions.dataInit)) { cm.editoptions = {dataInit: functionsMapping[cm.editoptions.dataInit]}; } }
    • setTimeout 毁了我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 2011-04-21
    • 2014-11-25
    • 1970-01-01
    • 2015-07-24
    相关资源
    最近更新 更多