jQuery UI Widgets Forums Lists DropDownList Accessing dropdown list values on page load when populated from data adapter

This topic contains 2 replies, has 2 voices, and was last updated by  Chaza96 11 months ago.

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

  • Chaza96
    Participant

    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?


    Martin
    Participant

    Hello Chaza96,

    Please, try adding async: false in the source:

    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,
    Martin

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


    Chaza96
    Participant

    Thanks 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

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

You must be logged in to reply to this topic.