jQuery UI Widgets › Forums › Lists › DropDownList › Accessing dropdown list values on page load when populated from data adapter
Tagged: dataadapter, DropDownList, jqxDropDownList, pageload, undefined
This topic contains 2 replies, has 2 voices, and was last updated by Chaza96 5 years, 10 months ago.
-
Author
-
February 26, 2019 at 11:05 pm Accessing dropdown list values on page load when populated from data adapter #104139
Hi team
The issue I’ve got is I need to access the value of the first item in a dropdown list as soon as the dropdown list is populated so I set my dropdown list to have the selected index as 1 using
var url = '@Url.Action("GetCustomersForUser", "Customer")'; var source = { datatype: 'json', datafields: [ { name: "customerId" }, { name: "customerName" }, { name: "customerAddress" }, { name: "customerContactNumber" }, { name: "Printers" }, { name: "StockLocations" }, { name: "UserCustomers" } ], url: url } var dataAdapterForCustomerDropdown = new $.jqx.dataAdapter(source); customerDropdown.jqxDropDownList({ source: dataAdapterForCustomerDropdown, displayMember: "customerName", valueMember: "customerId", selectedIndex: 0 });
The issue is that when I go to do something like this very soon after it returns undefined
console.log(customerDropdown.jqxDropDownList('getSelectedItem'));
How can I prevent this from occuring so that only when the data is loaded fully in that it works?February 27, 2019 at 8:26 am Accessing dropdown list values on page load when populated from data adapter #104145Hello Chaza96,
Please, try adding
async: false
in thesource
:var source = { datatype: 'json', datafields: [ { name: "customerId" }, { name: "customerName" }, { name: "customerAddress" }, { name: "customerContactNumber" }, { name: "Printers" }, { name: "StockLocations" }, { name: "UserCustomers" } ], url: url, async: false }
This should fix your issue.
Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/February 27, 2019 at 11:34 am Accessing dropdown list values on page load when populated from data adapter #104150Thanks Martin that appears to have done the trick please note that the documentation for the dataadapter needs updating to show that it should be placed in source as at the moment placing it in the settings for the dataadapter does not work but following the above does work
-
AuthorPosts
You must be logged in to reply to this topic.