jquery - Where can I convert JSON date format when data from WCF ajax call? -
i getting json data wcf service below format. binding data handsontables.
json
{"d":[ { "__type":"initdata:#company.reductiondata", "owner":"test9", ... ... "startdate":"\/date(1366848000000+0000)\/", "risks":"test9", }] }
jscript
$(function () { var $value = $("#body_hiddenclientid"); // alert($value.val()); var $container = $("#datatable"); $container.handsontable({ contextmenu: true, startrows: 1, minrows: 1, colheaders: true, stretchh: 'all', columns: [ { data: 'owner' }, ... .... { data: 'startdate', type: 'date', dateformat: 'mm/dd/yy' }, { data: 'risk' } ] }); var handsontable = $container.data('handsontable'); $.ajax({ url: "/editinitiatives.svc/getgriddata", data: "session=" + $value.val(), type: "get", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (res) { $container.handsontable('loaddata', res.d); }, error: function (error) { alert("error: " + error.responsetext); } }); });
i don't know how convert 'mm/dd/yy'
format? convert format in code?
handsontable expects string format date. should convert proper form.
try this:
change this:
... success: function (res) { $container.handsontable('loaddata', res.d); }, ...
with this:
... success: function (res) { for(var in res.d) { // milliseconds string "startdate":"\/date(1366848000000+0000)\/", // , create new date object var date = new date(+(res.d[i]['startdate'].match(/\d+/i))); // put format mm/dd/yy res.d[i]['startdate'] = (date.getmonth() + 1) + '-' + date.getdate() + date.getfullyear(); } $container.handsontable('loaddata', res.d); }, ...
Comments
Post a Comment