jQuery UI Widgets Forums Grid Display JSON data in a grid using dynamic column names?

Tagged: , , , ,

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • realtek
    Participant

    Hi,

    I have a JSON output which displays what I would like to use as the “Column Name” and also the data inside it.

    How can I use the dataAdapter/source to use the JSON field name as the actual grid column name rather than hard coding it on the grid?

    Thanks!


    realtek
    Participant

    Here is my code from the Grid I currently have, (hope its ok) – Basically, my JSON is built automatically from PHP json_encode. It will provide a list of columns and then the data which will always fit in the same columns sequentially.

    var url = "json/mainGrid.php"
    var source = {
    datatype: 'json',
    url: url,
    root: 'rowsinfo',
    cache: false,
    columns:[],
    beforeprocessing: function (data) {
    var columnsdata = new Array();
    for (k in data.columnsinfo){
    var col=[];
    col.text = data.columnsinfo[k]["DISPLAYNAME"];
    col.datafield = data.columnsinfo[k]["FIELDNAME"];
    columnsdata.push(col);
    source.columns = columnsdata;
    }
    $("#jqxgrid").jqxGrid({columns : source.columns});
    },
    data: {
    startcolumn: 1,
    }
    };

    Here is an example of my JSON Output (which could be wrong)

    {"columnsinfo":{"FIELDNAME":"SEQUENCE","DISPLAYNAME":"Test #"}}{"rowsinfo":{"Test #":"1"}}

    Dimitar
    Participant

    Hello realtek,

    Please refer to the forum topic Need to create grid columns dynamically from JSON for some tips on this matter.

    Best Regards,
    Dimitar

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

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

You must be logged in to reply to this topic.