jQuery UI Widgets › Forums › Grid › How to get nested json array in to dropdownlist cell
Tagged: data, DropDownList, editor, grid, jqxDropDownList, jqxgrid, json, map, mapping, source
This topic contains 4 replies, has 2 voices, and was last updated by Dimitar 10 years ago.
-
Author
-
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' } ] };
Is it not possible?
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,
DimitarjQWidgets team
http://www.jqwidgets.com/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?
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,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.