jQWidgets Forums
jQuery UI Widgets › Forums › Grid › CellsFormat is not working
This topic contains 4 replies, has 2 voices, and was last updated by sved 12 years, 5 months ago.
-
Author
-
Hello, I’m trying to format following json string in grid
“id”:”1″,”period_end”:”2012-10-07 00:00:00″,,”email_address”:”test@test.com”,”days”:”32″,”last_order”:”2012-09-05 00:00:00″,”lifetime”:”4″,”sales”:”51198.00″,”_profit”:”51198.00″,”value”:”12119.50″
with cellsformat, but with no success.
I’m using following code for formatting of last_order field:
{ text=”Last Order”, cellsformat=”d”, datafield=”last_order”, …}I’m trying to format the sales field too with format c2, but it didn’t format it as percent.
I’m applying following localization, but it didn’t work:var localizationobj = {};
localizationobj.firstDay =’1′;
localizationobj.percentsymbol = “%”;
localizationobj.currencysymbol = “$”;
localizationobj.currencysymbolposition = “before”;
localizationobj.decimalseparator = “,”;
localizationobj.thousandsseparator = ” “;Hi sved,
c2 is format for currency, not for percent. p2 is for percent.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comMy bad, I try it as p2, but still doesn’t work. date format is not working as well
Hi sved,
You have syntax issue in the posted data, there’s double “,,” after ”2012-10-07 00:00:00″
Here’s a working sample based on your code and implemented with jQWidgets 2.5.
<!DOCTYPE html><html lang="en"><head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.8.2.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.filter.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.edit.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script> <script type="text/javascript" src="../../jqwidgets/globalization/jquery.global.js"></script> <script type="text/javascript" src="../../scripts/gettheme.js"></script> <script type="text/javascript" src="generatedata.js"></script> <script type="text/javascript"> $(document).ready(function () { var theme = getTheme(); var data = '[{"id":"1","period_end":"2012-10-07 00:00:00","email_address":"test@test.com","days":"32","last_order":"2012-09-05 00:00:00","lifetime":"4","sales":"51198.00","_profit":"51198.00","value":"12119.50"}]'; var source = { datatype: 'json', localdata: data, datafields: [ { name: 'period_end', type: 'date' }, { name: 'days' }, { name: 'last_order', type: 'date' }, { name: 'sales', type: 'number' } ] }; var dataAdapter = new $.jqx.dataAdapter(source); $('#jqxgrid').jqxGrid( { source: dataAdapter, theme: 'classic', columns: [ { text: 'period_end', datafield: 'period_end', cellsformat: 'd', width: 90 }, { text: 'days', datafield: 'days', width: 90 }, { text: 'last_order', datafield: 'last_order', cellsformat: 'd', width: 90 }, { text: 'sales', datafield: 'sales', cellsformat: 'p2', width: 90 } ] }); }); </script></head><body class='default'> <div id="jqxgrid"> </div></body></html>
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks, I saw my errors, there was no type in datafields array.
-
AuthorPosts
You must be logged in to reply to this topic.