jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList Data not available after bindingComplete

Tagged: 

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

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

  • gkushner
    Participant

    I have a dropdownlist control that I want to set a specific value after it is done binding.

    It appears that the items collection is empty after bindingComplete. I was able to produce this on the JSFiddle demo site.
    When I run the below code the getItems method returns zero.

    Let’s say I want the drop down to default to “Breve” but I don’t know the index. What do I do? Thank you.

    var source = [
    “Affogato”,
    “Americano”,
    “Bicerin”,
    “Breve”,
    “Café Bombón”,
    “Café au lait”,
    “Caffé Corretto”,
    “Café Crema”,
    “Caffé Latte”];
    $(“#jqxDropDownList”).on(‘bindingComplete’, function (event) {
    alert($(“#jqxDropDownList”).jqxDropDownList(‘getItems’).length);
    });
    // Create a jqxDropDownList
    $(“#jqxDropDownList”).jqxDropDownList({
    source: source,
    theme: ‘energyblue’,
    width: ‘200px’,
    height: ’25px’,
    selectedIndex: 3,
    checkboxes: true
    });


    Peter Stoev
    Keymaster

    Hi gkushner,

    You don’t know the index. No problem. You have methods for selecting like selectItem. Ex: http://jsfiddle.net/jqwidgets/MysU4/

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    gkushner
    Participant

    Thank you for the response.

    But my problem is setting the selected item as soon as the data is loaded in BindingComplete.

    $(“#jqxDropDownList”).on(‘bindingComplete’, function (event) {
    alert($(“#jqxDropDownList”).jqxDropDownList(‘getItems’).length);
    });

    In this example getItems is [] so selectItem returns undefined.
    And selectItem causes “Uncaught TypeError: Cannot read property ‘selectIndex’ of null”

    We are loading data from AJAX/dataAdapter. I want to set the list to an item by a specific value immediately after loading completes.


    Peter Stoev
    Keymaster

    gkushner
    Participant

    Excellent. Thank you.

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

You must be logged in to reply to this topic.