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.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Populate array field dynamically #47252

    suleman1
    Participant

    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/n9xsBi8A

    My Json:-
    http://pastebin.com/xvJzEt8G

    Any Help will be really appreciated 🙂

    Thanks

    Populate array field dynamically #47253

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    Populate array field dynamically #47272

    suleman1
    Participant

    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.

    Populate array field dynamically #47283

    Peter Stoev
    Keymaster

    Hi suleman1,

    In the same beforeLoadComplete, you can build your columns array that will be used in the Grid.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    Populate array field dynamically #47353

    suleman1
    Participant

    Hi Peter ,

    I tried that too but can you elaborate it more with some actual code.? it will be really helpful.

    Thanks
    Suleman

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.