jQWidgets Forums
jQuery UI Widgets › Forums › Grid › How to render JSON obj. within a cell
Tagged: cellrenderer, datagrid control, jqxgrid
This topic contains 3 replies, has 2 voices, and was last updated by Peter Stoev 12 years, 5 months ago.
-
Author
-
Hey everyone. I’m very new to jqxGrid, and I’m trying to do something that isn’t working the way I thought it would. I have a column that needs to actually be a collapsed string that should come from JSON that looks like this:
"auto-vm-migration": { "genericMetricThresholds": { "numvms": "2", "mem": "1024", "cpu": "4" },}
I have mapping that looks like this:
{ name: 'gMetrics', map: 'auto-vm-migration>genericMetricThresholds'}
and the row I’m wanting to populate is configured like this:
{ text: 'GMetrics', datafield: 'gMetrics', renderer: columnrenderer, cellsrenderer: gmetricsCellRenderer, width: 218 }
Lastly, I have a function for gmetricsCellRenderer:
var gmetricsCellRenderer = function (row, column, value) { return '<div style="text-align: center;margin-top: 5px">
' + value + '</div>';}
I put a breakpoint (firebug) on that return statement, and I see that value looks like it isn’t even an object, but instead a string that looks like this “[Object object]”.
Where am I going wrong? Is this the wrong approach? Help?
Thanks in advance.
Hi newawd,
Please, take a look at this help topic: jquery-grid-datasources.htm. There are sections about loading of nested JSON into jqxGrid and how to correctly define the mapping.
Best Wishes,
Peter StoevjQWidgets Team
http://www.jqwidgets.comPeter, I’m already using that information to load a bunch of data from JSON. That is fairly easy. The problem is that I need to grab a dynamic number of key-> value pairs *within* that JSON location (auto-vm-migration>genericMetricThresholds), flatten them into a string, and then display them. I found one way to do it, but it requires that you pull the data from the server twice, which is just silly. No web dev worth his salt would want to pull all the data for the grid twice.
Is there a way to pull the data at auto-vm-migration>genericMetricThresholds, manipulate the JSON object located at that point, format it into a string, and then display it in the field?
Thanks
Hi newawd,
If you want to manipulate what’s loaded, see the ‘beforeLoadComplete’ callback of jqxDataAdapter. For more information, see: jquery-data-adapter.htm.
Best Wishes,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.