jQWidgets Forums
jQuery UI Widgets › Forums › Grid › JSON and newline char
This topic contains 12 replies, has 3 voices, and was last updated by Jane 11 years, 6 months ago.
-
AuthorJSON and newline char Posts
-
Hi,
Is it possible create a grid from JSON data they contain a newline character? We tried html tag but when we move the scrollbar was displayed :
“text text”
and when you load the grid is showing
“text
text”Can you help me?
Thanks
JaneHello Jane,
Yes, it is possible. Please check the following example, based on the demo Binding to JSON:
<!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.2.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.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: 'int' }, { 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, autorowheight: true, autoheight: 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>
excerpt from beverages.txt:
[{ "id": "1", "name": "Hot Chocolate", "type": "Chocolate Beverage", "calories": "370", "totalfat": "16g", "protein": "14g"}, { "id": 2, "name": "Peppermint<br />Hot Chocolate", "type": "Chocolate Beverage", "calories": "440", "totalfat": "16g", "protein": "13g"}, { "id": "3", "name": "Salted Caramel<br />Hot Chocolate", "type": "Chocolate Beverage", "calories": "450", "totalfat": "16g", "protein": "13g"}, {...
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thank you,
we tested but the problem is in scrollbar. When you move scroollbar, jqxGrid show this data as follows:
Peppermint < br Hot Chocolate (show br)
When the data load. The jgxGrid show this data as follows:
Peppermint
Hot ChocolateExcuse my English, it is not good
JaneHi guys,
Just an update from me on this topic. It is not possible to display HTML Content in the Grid cells unless you set the “cellsrenderer” callback of the column. The built-in cells rendering is for displaying Text only.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi,
I do not use “cellsrenderer” and the result is same. When I move scollbar the grid show BR tag . I think it is not independent on function “cellsrenderer”. It happens in the example above. This example shows a br tag with parentheses and without a backslash when you move scrollbar.
Jane
Hi Jane,
The problem is that you do not use “cellsrenderer” and you want to display Tags within the cells. The built-in rendering works with Text, not with Tags.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi,
Is there any other way how to display new line without html tag br?
Thanks
JaneHi Jane,
In cellsrenderer you may also have other HTML tags which add a new line after their content, such as div or p.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi,
my problem is independent of the HTML tag. When I use br, div or p HTML tag the result is same. First rendering is good, but when I move horizontal scrollbar the grid is rendering bad, becouse it shows HTML tags. End tag shows without backslah. You can also try the example presented here and second rendering will be bad. We have HTML tags include in JSON.
We use jqwidgets version 3.0.1.
Hi Jane,
The only way to effectively insert HTML tags in a grid cell is through the cellsrenderer callback function.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi,
Thanks. Do you think about support for HTML tags in JSON?
Jane
Hi Jane,
The functionality is supported through cellsrenderer. Here is an updated version of the example with it:
<!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.2.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.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: 'int' }, { name: 'totalfat', type: 'string' }, { name: 'protein', type: 'string' } ], id: 'id', url: url }; var dataAdapter = new $.jqx.dataAdapter(source); var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) { return '<span style="margin: 4px; float: ' + columnproperties.cellsalign + ';">' + value + '</span>'; }; $("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, theme: theme, columnsresize: true, autorowheight: true, autoheight: true, columns: [ { text: 'Name', datafield: 'name', width: 250, cellsrenderer: cellsrenderer }, { 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/Hi,
the example was very helpfull for me. Thanks. Me code works good now
Thanks
Jane -
AuthorPosts
You must be logged in to reply to this topic.