jQWidgets Forums
jQuery UI Widgets › Forums › Grid › How to get nested json array in to dropdownlist cell .. revisited
This topic contains 4 replies, has 2 voices, and was last updated by Hristo 8 years, 6 months ago.
-
Author
-
December 29, 2016 at 4:02 am How to get nested json array in to dropdownlist cell .. revisited #90172
Hi. I am a novice at javascript so please bear with me.
I have my nested grid with data from mysql-php-json working. I get data in the main and nested parts of the grid fine. I now want to fill a dropdownlist with options. I tried following one of your response to another persons similar question but I have failed to get it to work.
I feel like my problem is here. This was one of your answers to the similar question. Is the ‘0>’ (zero) correct before the ‘order>trucks’?
” root: ‘0>order>trucks’ ”When I add this to my “root” in addition to changing my JSON output my grid goes empty. As well I get these to script errors:
TypeError: this.detailboundrows is undefined
TypeError: o is nullThank you for any help you can give me.
//------------------- // setup grid //------------------- var source = { datatype: "json", datafields: [ { name: 'lotnumValue', type: 'number' }, { name: 'customers', type: 'string' }, { name: 'truckNames', type: 'string' }, { name: 'delivery instructions', type: 'string' } ], id: 'lotnumValue', url: 'dashboard_ordersData.php?lotnumValue='+lotnumP, root: '0>order>trucks', cache: false, beforeprocessing: function (data) { source.totalrecords = data.products; } }; var dataAdapter = new $.jqx.dataAdapter(source); dataAdapter.dataBind(); //------------------ // JSON DATA //------------------ [{ "order": { "lotnumValue": "100511", "delivery instructions": "", "customers": "River City Produce", "trucks": [ { "truckNames": "CHR" }, { "truckNames": "Karr" }, { "truckNames": "A&S" }, { "truckNames": "A&A" }, { "truckNames": "MOTUS" } ] }, "products": 1 }]
December 29, 2016 at 10:53 am How to get nested json array in to dropdownlist cell .. revisited #90182Hello killerhair,
Please, take a look at this example:
https://www.jseditor.io/?key=dataadapter-with-jsonBest Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comDecember 29, 2016 at 6:20 pm How to get nested json array in to dropdownlist cell .. revisited #90193Thanks for the help Hristo. I am now getting what you see in the attached screen shot:
To simplify, I commented out my nested grid for now just to try to get my dropdown working. To reduce the code example below I just removed all the columns I use and just show my dropdownlist column.
My json data is in the same format as before. Its the same as your example. Thanks again for helping!
`
//———————
// prepare main source
//——————–
var source =
{
datatype: “json”,
datafields: [
{ name: ‘truckNames’, map: ‘trucks’ },
],
id: ‘lotnumValue’,
url: ‘dashboard_ordersData.php?lotnumValue=’+lotnumP,
root: ‘order’
};
var dataAdapter = new $.jqx.dataAdapter(source);
dataAdapter.dataBind();
//————————-
// init main grid
//————————-
var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) {
return ‘<span style=”margin: 4px; margin-right: 5px; font-size: 10px; float: ‘ + columnproperties.cellsalign + ‘;”>’ + value + ‘</span>’;
}
$(“#jqxgrid”).jqxGrid(
{
source: dataAdapter,
theme: ‘dark’,
width: ‘100%’,
autoheight: true,
autorowheight: true,rendergridrows: function () {
return dataAdapter.records[0];
},columns: [
{ text: ‘trucks’, datafield: ‘truckNames’, columntype: ‘dropdownlist’, width: ‘5%’, cellsrenderer: cellsrenderer },
]
});December 30, 2016 at 4:37 pm How to get nested json array in to dropdownlist cell .. revisited #90210Any ideas about the [object Object] ???
Ignore this in my last post: return dataAdapter.records[0];
My code is like this: return dataAdapter.records;My code is exactly like your example but I cannot figure out what is missing, but it sure seems like it should be a simple thing.
Hello killerhair,
I would like to ask you why you use
rendergridrows
it is used when “the grid is used in virtual mode”.
Also, what you mean about"Any ideas about the [object Object] ???"
? If you talk about the first message in the console.
It is an object that has members as the datafields.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.