jQuery UI Widgets Forums Grid Grid with JSON Source w/ Object

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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Grid with JSON Source w/ Object #63977

    shepa006
    Participant

    I have a json source with items that include attributes (such as text and numbers) as well as objects {}. Can the dataAdapter and Grid read the item objects? If so, how do I set up the column to read them?

    Here’s a sample json structure that I’m talking about:

    var data = [
        {
            "salesPerson": {
                "firstname": "john",
                "lastname": "smith"
            },
            "productname": "product 1",
            "price": 1,
            "quantity": 2,
            "total": 2
        },
        {
            "salesPerson": {
                "firstname": "jane",
                "lastname": "adams"
            },
            "productname": "product 2",
            "price": 4,
            "quantity": 5,
            "total": 20
        },
        {
            "salesPerson": {
                "firstname": "jane",
                "lastname": "adams"
            },
            "productname": "product 5",
            "price": 7,
            "quantity": 8,
            "total": 56
        },
        {
            "salesPerson": {
                "firstname": "bill",
                "lastname": "brown"
            },
            "productname": "product 4",
            "price": 3,
            "quantity": 4,
            "total": 12
        }
    ];
    
    var source =
    {
        localdata: data,
        datatype: "json"
    };
    
    // now that the json data is built use the jqx adapter to handle the data
    var dataAdapter = new $.jqx.dataAdapter(source, {
        loadComplete: function (data) {
            console.log("Data loaded");
            console.log(data);
        },
        loadError: function (xhr, status, error) {
            console.error("Data failed to load into jqx adapter\n\t" + status + " \n\t" + error);
        }
    });

    /*
    I tried setting up a column using
    { text: ‘First Name’, datafield: ‘salesPerson.firstname’, width: 100 },
    but the column was blank
    */

    Grid with JSON Source w/ Object #63986

    Dimitar
    Participant

    Hello shepa006,

    In this case, you need datafield mapping. To learn about this functionality, please refer to the guide Grid Data Sources. You can find examples of XML and JSON mapping there.

    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.