jQWidgets Forums

jQuery UI Widgets Forums Grid Add to Grid

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 11 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Add to Grid Posts
  • Add to Grid #22901

    davijeb
    Blocked

    My grid has the following JSON:

    {a:1, b:2, c[x:1, y:1]}

    So, when I define the grid datafields they are:

    datafields: [
    { name : 'char_a', map : 'a'},
    { name : 'char_b', map : 'b'},
    { name : 'char_x', map : 'c>x'},
    { name : 'char_y', map : 'c>y'}
    ]

    Which works fine. Now, I want to add another row to the table for the following json:

    var json = {a:2, b:3, c[x:4, y:5]}
    $('#jqxgrid').jqxGrid('addrow', null, json);

    But this won’t work as it expects the data in the format:

    var json = {a:2, b:3, x:4, y:5}

    Is there a way to ask the grid to convert the data (it does this anyway) and then add it?

    Add to Grid #22933

    Dimitar
    Participant

    Hello davijeb,

    You may convert the data the same way you did with your source – using data adapter with the same datafields and mapping but with with the json variable set as localdata. Then you should call dataadapter.dataBind() and use the dataadapter.records array to access your data in the correct format.

    Another possibility (which may be a better one) is to use a custom converter function, e.g.:

    var convertJSON = function (json) {
    var convertedJSON = new Object();
    convertedJSON = { a: json.a, b: json.b, x: json.c.x, y: json.c.y }
    return convertedJSON;
    };
    var json = { a: 2, b: 3, c: { x: 4, y: 5} };
    json = convertJSON(json);

    We hope these tips were helpful to you.

    Best Regards,
    Dimitar

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

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

You must be logged in to reply to this topic.