doctrine返回datetime对象而不是date字符串,jqGrid jsonmap不工作 [英] Doctrine returning datetime object instead of date string, jqGrid jsonmap not working

查看:252
本文介绍了doctrine返回datetime对象而不是date字符串,jqGrid jsonmap不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的jqgrid中显示日期。但是,doctrine会返回一个datetime对象,而不是jqgrid可以显示的正常字符串类型值。



我可以想到两种可能的解决方案:



(1)更改doctrine的返回类型以某种方式返回一个字符串,以便jqgrid可以显示它,而没有问题。 (目前,json正在返回一个对象)



(2)使用jsonmap来操纵json(datetime作为一个对象进来,但它内部显示正确的数据)



我的代码:



(Doctrine related)

  $ qb = $ this-> em-> getRepository('ProductOrderLookupBundle:Product') - > createQueryBuilder('u'); 
$ qb-> select('u.id,u.productName,u.productDetails,u.shipDate,u');
$ qb-> getArrayResult();

(Jqgrid相关)

  jQuery(document).ready(function(){
jQuery(#list)。jqGrid({
url:{{asset('/ app_dev.php / _ $ thr,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, '产品详细信息','装运日期','动作'],
colModel:[
{name:'id',index:'u.id',width:200},
{name:'productName',index:'u.productName',width:200,editable:true},
{name:'productDetails',index:'u.productDetails',width:200,align:' right',editable:true},
{name:'shipDate',index:'u.shipDate',可编辑:true,jsonmap:function(obj){return getVaueByName(obj.cells,date); }},
{name:'actions',index:'a ctions',sortable:false,search:false}
],
其他jqgrid相关代码
var getVaueByName = function(cells,colName){
var i,count = cells。长度,项目; (i = 0; i< count; i + = 1)的
{
item = cells [i];
if(item.colname === colName){
return item.value;
}
}
return'';
};

我的json

 code> {
page:1,
total:20000,
records:1000000,
rows:
[
{id:1,cell:[1,Door,Details,{date:2012-06-18 00:00:00,timezone_type时区:欧洲\\ /巴黎}]},
{id:2,cell:[2,Door2,Details2,{date 18 00:00:00,timezone_type:3,timezone:Europe \ / Paris}]},
{id:3,cell:[3,Door3 ,Details3,{date:2012-06-18 00:00:00,timezone_type:3,timezone:Europe \ / Paris}]},
{ id:4,cell:[4,Door4,Details4,{date:2012-06-18 00:00:00,timezone_type:3,timezone \\/巴黎}]},
{id:5,cell:[5,Door5,Details5,{date:2012-06-18 00:00: 00,timezone_type:3,timezone:Europe \ / Paris}]},
{id:6,cell:[6,Door6,Details6 {date:2012-06-18 00:00:00,timezone_type:3,timezone:Europe \ / Paris}]},
{id 小区:[7, Door7, Details7, {date:2012-06-18 00:00:00,timezone_type:3,timezone:Europe \ / Paris}]},
{id cell:[8,Door8,Details8,{date:2012-06-18 00:00:00,timezone_type:3,timezone:Europe \ / Paris }},
{id:9,cell:[9,Door9,Details9,{date:2012-06-18 00:00:00,timezone_type :3,timezone:Europe \ / Paris}]},
{id:10,cell:[10,Door10,Details10,{date 2012-06-18 00:00:00,timezone_type:3,timezone:Europe \ / Paris}}}
]
}

在这一切我想要的是日期列下的值。到目前为止,我已经尝试过



它使用 jsonReader:{repeatitems:false} 首先,但它使用另外 jsonmap 属性在 colModel 的每一列中:

  colModel:[
{name:'id',index:'u.id',width:110},
{name:'productName',jsonmap: cell.1,index:'u.productName',width:120,editable:true},
{name:'productDetails',jsonmap:cell.2,inde x:'u.productDetails',width:120,align:'right',editable:true},
{name:'shipDate',jsonmap:cell.3.date,index:'u.shipDate ',align:center,formatter:date,editable:true,width:120},
{name:'actions',formatter:actions,width:70,align:center sortable:false,search:false}
]

jsonmap:cell.1通知从单元格属性首先读取,然后获取 1 元素单元格。要读取日期,需要使用 jsonmap:cell.3.date。可以使用另一种功能形式的 jsonmap

  jsonmap:function obj){return obj.cell [1]; } //阅读productName 

  jsonmap:function(obj){return obj.cell [3] .date; } //读取日期


I'm trying to display date in my jqgrid. But doctrine is returning a datetime object instead of a normal string type value which jqgrid can display.

I can think of two possible solutions:

(1) Change doctrine's return type to somehow return a string so that jqgrid can display it without a problem. (Currently the json is returning an object)

(2) Use jsonmap to manipulate the json (The datetime is coming in as an object but it does display proper data inside)

My code:

(Doctrine related)

$qb = $this->em->getRepository('ProductOrderLookupBundle:Product')->createQueryBuilder('u');
$qb->select('u.id, u.productName, u.productDetails,u.shipDate, u');
$qb->getArrayResult();

(Jqgrid related)

jQuery(document).ready(function(){
            jQuery("#list").jqGrid({
                url:"{{ asset('/app_dev.php/_thrace-datagrid/data/user_management') }}",
                datatype: 'json',
                mtype: 'POST',
                colNames:['Product ID','Product Name', 'Product Details', 'Shipment Date', 'Actions'],
                colModel :[
                    {name:'id', index:'u.id', width:200},
                {name:'productName', index:'u.productName', width:200, editable: true},
                {name:'productDetails', index:'u.productDetails', width:200, align:'right', editable: true},
                {name:'shipDate', index: 'u.shipDate', editable: true,jsonmap: function (obj) { return getVaueByName(obj.cells, "date"); }},
                {name:'actions',index:'actions',sortable:false, search:false}
            ],
other jqgrid related code
var getVaueByName = function (cells, colName) {
        var i, count = cells.length, item;
        for (i = 0; i < count; i += 1) {
            item = cells[i];
            if (item.colname === colName) {
                return item.value;
            }
        }
        return '';
    };

My json

{
  "page":1,
  "total":20000,
  "records":1000000,
  "rows":
    [
      {"id":1,"cell":[1,"Door","Details",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":2,"cell":[2,"Door2","Details2",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":3,"cell":[3,"Door3","Details3",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":4,"cell":[4,"Door4","Details4",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":5,"cell":[5,"Door5","Details5",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":6,"cell":[6,"Door6","Details6",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":7,"cell":[7,"Door7","Details7",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":8,"cell":[8,"Door8","Details8",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":9,"cell":[9,"Door9","Details9",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]},
      {"id":10,"cell":[10,"Door10","Details10",{"date":"2012-06-18 00:00:00","timezone_type":3,"timezone":"Europe\/Paris"}]}
    ]
}

In this all I want is the value under date column. so far I've tried this and this . Both are front end related. I have not been able to find doctrine related solutions. I cannot use jsonReader: { repeatitems: false } because it doesn't load my data for some reason.

This is what my current grid looks like

Any kind of solution will be appreciated.

Thanks

解决方案

What you can do is something like the following: http://jsfiddle.net/OlegKi/0fvajwhp/

It uses jsonReader: { repeatitems: false } first of all, but it uses additionally jsonmap property in every column of colModel:

colModel: [
    {name: 'id', index:'u.id', width: 110},
    {name: 'productName', jsonmap: "cell.1", index:'u.productName', width: 120, editable: true},
    {name: 'productDetails', jsonmap: "cell.2", index:'u.productDetails', width: 120, align:'right', editable: true},
    {name: 'shipDate', jsonmap: "cell.3.date", index: 'u.shipDate', align: "center", formatter: "date", editable: true, width: 120 },
    {name: 'actions', formatter: "actions", width: 70, align: "center", sortable:false, search:false}
]

The value jsonmap: "cell.1" inform to read first from cell property and then get 1 element of the cell. To read the date one need to use jsonmap: "cell.3.date". One can use alternatively function form of jsonmap:

jsonmap: function (obj) { return obj.cell[1]; } // to read productName

and

jsonmap: function (obj) { return obj.cell[3].date; } // to read date

这篇关于doctrine返回datetime对象而不是date字符串,jqGrid jsonmap不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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