jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList Cannot set initial selected value

This topic contains 2 replies, has 1 voice, and was last updated by  ajcs 5 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Cannot set initial selected value #108014

    ajcs
    Participant

    With the following code it will not set the initial value of the drop down list. The list does not get anything selected.

    I try to set the selected Id to 19 which is a valid value. I notice when I debug that the data adapter has not loaded any records at that point. Does it auto load when I try to set the list val or do I need to force it to load the records first?

    After this the drop down list is functioning and showing all records – it just does not get the initial value selected – please help.

    var ClassesDataSource =
    {
    dataType: “json”,
    root: “Data”,
    dataFields: [
    { name: ‘Id’, type: ‘number’ },
    { name: ‘Description’, type: ‘string’ }
    ],
    id: ‘Id’,
    url: ‘/Attributes/GetAttributeClasses’
    }

    var ClassesDataAdapter = new $.jqx.dataAdapter(ClassesDataSource,
    {
    loadError: function (jqXHR, status, error) {
    alert(“There was an error please contact support”);
    },
    }
    );

    $(“#cmb”).jqxDropDownList({
    autoDropDownHeight: true,
    source: ClassesDataAdapter,
    valueMember: ‘Id’,
    displayMember: ‘Description’
    });

    // Try to set the selected value. This does not work – nothing is selected.
    // 19 is an existing Id in the list.
    $(“#cmb”).jqxDropDownList(‘val’, ’19’);

    Cannot set initial selected value #108016

    ajcs
    Participant

    I solved this. I needed to do the following instead – but not in the $(document).ready event – later on
    $(“#cmb”).jqxDropDownList(‘selectItem’, 19);

    Cannot set initial selected value #108020

    ajcs
    Participant

    You can do it right away but you have set to async: false on the data source

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

You must be logged in to reply to this topic.