jQWidgets Forums
jQuery UI Widgets › Forums › Grid › How to parse a datafield from JSON into two separate columns in the grid?
Tagged: datagrid json, jquery grid json, json
This topic contains 4 replies, has 2 voices, and was last updated by qtipaddict 10 years, 11 months ago.
-
Author
-
June 10, 2014 at 5:42 pm How to parse a datafield from JSON into two separate columns in the grid? #55657
I want to load the following GeoJSON snippet into a grid.
{ "features": [ { "geometry": { "type": "Point", "coordinates": [ -60.8018955073674, 32.269613547693 ] } } ] }
Here is my code:
var source = { datatype: "json", datafields: [ { name: 'coordinates', map: 'geometry>coordinates', type: 'string'} ], url : url, root: "features" };
Is there any way to parse the coordinates array in order to create two columns in the grid for “latitude” and “longitude”? If so, where and how do I do this?
June 11, 2014 at 5:04 am How to parse a datafield from JSON into two separate columns in the grid? #55678Hi qtipaddict,
You can add two data fields instead of one and your mapping would be: ‘geomerty>coordinates>0’ and ‘geometry>coordinates>1’
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comJune 11, 2014 at 7:38 pm How to parse a datafield from JSON into two separate columns in the grid? #55747Thanks Peter, that worked! Now I want to format the values in the grid so that 39.404066147905 appears as 39.40. I tried
{ text: 'Latitude', datafield: 'latitude', cellsformat: 'f2' },
but the grid still shows 39.404066147905. I don’t get it.
June 11, 2014 at 8:54 pm How to parse a datafield from JSON into two separate columns in the grid? #55748I think I figured it out.
var columnsrenderer = function (value) { return '<div style="text-align: center; margin-top: 5px;">' + value + '</div>'; } { text: 'Latitude', datafield: 'latitude', width: 200, editable : false, renderer: columnsrenderer, cellsalign: 'center', cellsformat: 'f2' },
I was using a cellsrenderer which I guess overrides cellsformat. Is there way I can incorporate cellsformat into a div so I can use my cellsrenderer?
June 11, 2014 at 10:56 pm How to parse a datafield from JSON into two separate columns in the grid? #55749What should I do when the JSON is an array of arrays? “geometry>coordinates>0” returns nothing and “geometry>coordinates>1” returns 10 if I define the datafield as a float. If I don’t define the type, it returns a comma-separated string.
"coordinates": [ [ [ 10, 10 ], [ 20, 10 ], [ 20, 20 ], [ 10, 20 ], [ 10, 10 ] ] ]
-
AuthorPosts
You must be logged in to reply to this topic.