jQuery UI Widgets Forums Grid How to get nested json array in to dropdownlist cell

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

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

  • genachka
    Participant

    How can I get the inner json array to be displayed in a grid’s dropdownlist?

    I tried mapping: name: 'cityName', map: 'state>city>name' but I get back nothing. If I force it to first element in city’s item (name: 'cityName', map: 'state>city>0>name'), I get data back but of course I need more than 1 element to be displayed in the dropdownlist of a cell in the grid.

    I modified your sample data for nested to illustrate my json, where city is the array:

    var data = [
        {
            "state": {
                "id": "x526",
                "city": [
                {
                    "name": "Beverly Hills",
                    "id": 90210,
                    "value": "Beverly Hills"
                },
                {
                    "name": "Another Beverly Hills",
                    "id": 10210,
                    "value": "Another Beverly Hills"
                }]
            }
        }
    ];
    
    var source = {
        datatype: 'json',
        localdata: data,
        datafields:
        [
            {
                name: 'cityName', map: 'state>city>name'
            }
        ]
    };

    genachka
    Participant

    Is it not possible?


    Dimitar
    Participant

    Hello genachka,

    Here is the correct mapping you need to set:

    var data = [{
        "state": {
            "id": "x526",
            "city": [{
                "name": "Beverly Hills",
                "id": 90210,
                "value": "Beverly Hills"
            }, {
                "name": "Another Beverly Hills",
                "id": 10210,
                "value": "Another Beverly Hills"
            }]
        }
    }];
    
    var source = {
        datatype: 'json',
        localdata: data,
        datafields: [{
            name: 'name',
            type: 'string'
        }, {
            name: 'id',
            type: 'number'
        }, {
            name: 'value',
            type: 'string'
        }],
        root: '0>state>city'
    };
    var dataAdapter = new $.jqx.dataAdapter(source);
    dataAdapter.dataBind();

    Best Regards,
    Dimitar

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


    genachka
    Participant

    Hmm interesting. I’ll give that a shot.

    I notice that when a dropdown list is used in a grid and checkboxes are enabled for the values that after you select the items, it separates them with a comma. Does it means that if I get the multiple values read from the JSON for city that it will on initial display in the grid be also comma separated?


    Dimitar
    Participant

    Hi genachka,

    No, that is not the case. If you wish comma separated initial values, you would have to concatenate the values before loading and load only a single value in a particular grid cell.

    Best Regards,
    Dimitar

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

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

You must be logged in to reply to this topic.