jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Populate array field dynamically
This topic contains 4 replies, has 2 voices, and was last updated by suleman1 11 years, 3 months ago.
-
Author
-
Hi,
I have just started working with Jqxgrid and really finding it extremely helpful in my tasks.
The problem I was facing today was I successfully got my JSON working , but my JSON have an array of integers also, like this"Baseline: [2,2,2,2,2,2,2,2,2,2]
what I want is to display all indexes in separate small cells, I tried different things but was not successful, What I am getting right now is array is just coming in one cell like a string, I want to dynamically assign each array index to a separate cell.What I am getting now is:-
http://postimg.org/image/umpwy1sef/My Code:-
http://pastebin.com/n9xsBi8AMy Json:-
http://pastebin.com/xvJzEt8GAny Help will be really appreciated
Thanks
Hi suleman1,
You can use the “beforeLoadComplete” callback function of jqxDataAdapter to modify your data array before loading it in the Grid. See: http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxdataadapter/jquery-data-adapter.htm. You can split your BaseLine array into multiple baseline1, baseline2, etc. datafields and populate the Grid after that where you will end up with columns like “baseline1, baseline2, etc”.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Thank you for your reply Peter, I hope my questions will also help others if they face the same hurdles.
So What I did was in beforeLoadComplete added datafields dynamically, it created several more datafields of all array elements. But now I can’t figure out how to render columns , my beforeLoadComplete function looks like this,
beforeLoadComplete: function (records, original) { for (var i = 0; i< records[0].Baseline.length; i++) { source.datafields.push({name: 'Cell'+ i, columngroup:'Baseline', map: 0 }); } }
I know my code could be wrong too, but if you could help me and correct it it would be really great..!!
Thank you for your replies and help.
Hi suleman1,
In the same beforeLoadComplete, you can build your columns array that will be used in the Grid.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi Peter ,
I tried that too but can you elaborate it more with some actual code.? it will be really helpful.
Thanks
Suleman -
AuthorPosts
You must be logged in to reply to this topic.