jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Bug with json data
This topic contains 5 replies, has 2 voices, and was last updated by cosostones 11 years, 8 months ago.
-
AuthorBug with json data Posts
-
Hello,
According to this post : http://www.jqwidgets.com/community/topic/editing-jqxgrid-with-combobox-column/, I tried to put a null value in a column with type ‘string’ but in my case the data are json formated and this doesn’t works.
I host a sample with a video with two grids :
– the one on the left with array data,
– the other one with json data.
Link : http://sdrv.ms/14x5qAY.
Regards.
May I have a response please ?
Regards.
Hello cosostones,
Please take a look at the following sample (based on the demo Binding to JSON). A cell from the column Calories can have a blank value.
<!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.10.1.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.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/jqxmenu.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.edit.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.columnsresize.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../scripts/gettheme.js"></script> <script type="text/javascript"> $(document).ready(function () { var theme = getDemoTheme(); var url = "../sampledata/beverages.txt"; // prepare the data var source = { datatype: "json", datafields: [ { name: 'name', type: 'string' }, { name: 'type', type: 'string' }, { name: 'calories', type: 'string' }, { name: 'totalfat', type: 'string' }, { name: 'protein', type: 'string' } ], id: 'id', url: url }; var dataAdapter = new $.jqx.dataAdapter(source); $("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, theme: theme, columnsresize: true, editable: true, columns: [ { text: 'Name', datafield: 'name', width: 250 }, { text: 'Beverage Type', datafield: 'type', width: 250 }, { text: 'Calories', datafield: 'calories', width: 180 }, { text: 'Total Fat', datafield: 'totalfat', width: 120 }, { text: 'Protein', datafield: 'protein', minwidth: 120 } ] }); }); </script></head><body class='default'> <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;"> <div id="jqxgrid"> </div> </div></body></html>
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hello Dimitar,
I looked at the sample and the problem is the same, in the source the ‘calories’ field is a string if we change this to an int it doesn’t accept null value.
Regards.
Hi cosostones,
Setting the type to “string” is the solution to this issue. Another workaround is to use cellsrencerer, e.g.:
{ text: 'Calories', datafield: 'calories', width: 180, cellsrenderer: function (value) { if (value == 0) { return ""; } else { return value; };}},
In this case, the “calories” datafield can be “int”.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hello,
Thanks for the workaround but I don’t understand why there is a column type if the datatype of the source override it.
If other people wants to apply this workaround they should change the parameters of the cellsrenderer method to :
cellsrenderer = function(row, columnfield, value, defaulthtml, columnproperties)
Regards.
-
AuthorPosts
You must be logged in to reply to this topic.