jqGrid的 - 使用日期选择器与动态colModel [英] jqgrid - use datepicker with dynamic colModel

查看:1271
本文介绍了jqGrid的 - 使用日期选择器与动态colModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到问题关于实施日期选择器与jqGrid的。我觉得这个问题太具体。我想知道,有没有人能够实现与动态jqGrid的一个日期选择器?通过Ajax请求的colModel,colNames,在我的情况下,生成的数据服务器端,然后显示在本地。在服务器上,在PHP中,我创建了colModel结构的数组,然后JSON EN code将其发送回客户端。有效的JSON放在引号内的钥匙,但根据实例<一href="http://stackoverflow.com/questions/3041097/how-to-use-monthnames-in-jqgrid-when-validating-date/3041580#3041580">here, 这里和(重要)的此处,我不应该这样做。

我试图用正则表达式来删除引号,但只是导致一个JavaScript错误,因为它再也不能解析现在已经无效JSON。

时的日期选择器与动态colModel可能吗?

下面是AJAX请求:

  $(文件)。就绪(函数(){
  $阿贾克斯({
   键入:GET,
   数据类型:JSON,
   成功:函数(结果){
    尝试{
     //警报(结果);
     结果= jQuery.parseJSON(结果);
    }赶上(错误){
     警报(错误是成功的JSON+ ERR);
     返回;
    }
    VAR科隆= result.colNames;
    VAR科尔姆= result.colModelList;
    VAR冷= result.colDataList;
    grid.jqGrid({
     数据类型:本地,
     colNames:科隆,//列名
     colModel:科尔姆,//列选项
     数据:性寒,//表数据
     editurl:clientArray',//改变不会被发送到服务器
     cellEdit:真正的,
     cellsubmit:clientArray,
    });
   }
  });
});
 

和一个例子colModel:

  {
 编辑:真实,
 名:日,
 指数:日,
 sorttype:日,
 editrules:{日期:真},
 editoptions:{dataInit:initDateEdit}
}
 

解决方案

看<一href="http://stackoverflow.com/questions/5171617/how-to-add-custom-formatter-for-jqgrid-with-dynamic-column-binding/5175127#5175127">this答案。它应该解决您的问题。

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"}
}

解决方案

Look at this answers. It should solve your problem.

这篇关于jqGrid的 - 使用日期选择器与动态colModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆