jQWidgets Forums

jQuery UI Widgets Forums Grid dynamic columns depending on db table

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

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

  • omargarro
    Participant

    Hi, I want to implement a jqxgrid where the columns to display are stored in a db table.

    I tried:
    var cols;
    $.ajax({
    url: ‘contracts/getColumnsName.php’, cache: false, type: ‘post’,
    success: function (response) {
    cols = response;
    // php returns response as:
    // [{text: “Full Name”, datafield: “fullName”, width: 100]}, {text: “e-mail”, datafield: “email”, width: 200]}]
    }
    });

    $(“#vals”).jqxGrid( {
    width: 680, height: 540, theme: ‘energyblue’, columnsresize: true, sortable: true,
    columns: cols
    });

    well this is not working

    what i think is that cols is expected to be object type. and if I alert( typeof(cols) ) inside ajax call, it returns “string”.

    how can I solve this ?


    Dimitar
    Participant

    Hi omargarro,

    Using JSON.parse() you can convert your string to an object. But there is also another thing – the Ajax call might not be complete by the time you try to initialize the grid. We suggest you call the grid initialization code in success, too.

    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.