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