jQWidgets Forums

jQuery UI Widgets Forums Lists ListBox List box doesnt populate

Tagged: 

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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • List box doesnt populate #18348

    w424637
    Member

    Sometimes when i run my page my list box only shows:

    Please Choose:

    It doesn’t have my json list of values inside it.

    Other times it brings back my list – but always defaulting to the first item in my list – not the Please Choose: which isn’t in my list at all.

    Any ideas? Code below:

    $(document).ready(function () {
    var theme = getDemoTheme();
    // prepare the data
    var source =
    {
    datatype: “json”,
    datafields: [
    { name: ‘CompanyName’},
    { name: ‘ContactName’}
    ],
    url: ‘data.php’,
    async: false
    };
    var dataAdapter = new $.jqx.dataAdapter(source);

    $(“#dropdownlist”).jqxDropDownList(
    {
    source: dataAdapter,
    theme: theme,
    width: 250,
    height: 25,
    selectedIndex: 0,
    displayMember: ‘ContactName’,
    valueMember: ‘CompanyName’
    });
    $(‘#sendButton’).jqxButton({ width: 70, theme: theme });
    });

    thanks
    Simon

    List box doesnt populate #18349

    Peter Stoev
    Keymaster

    Hi Simon,

    The posted code will always select the first item from the loaded items, because the “selectedIndex” is set to 0. Your Ajax call is synchronous so the widget will display the first loaded item(if any items are loaded). If your server is not responsive for some reason and the widget is not populated with data, then it will display “Please Choose:” – the promptText message.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    List box doesnt populate #18352

    w424637
    Member

    OK – it seems sometimes it populates slower than other times meaning it doesn’t always populate.

    When it does populate – can i have it so it defaults to Please choose: as option 1 and then lists my own items?

    S

    List box doesnt populate #18353

    Peter Stoev
    Keymaster

    Hi Simon,

    If you do not want to have a default selected item, do not set the selectedIndex property.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    List box doesnt populate #18354

    w424637
    Member

    great – many thanks

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

You must be logged in to reply to this topic.