Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / Select item from igCombo by Value

Select item from igCombo by Value

New Discussion
Thomas Fang
Thomas Fang asked on May 5, 2016 8:36 AM

I’m loading JSON data into an igCombo via the dataSource property. I’ve set the valueKey of the igCombo to a property of the JSON data. I would like to select an item from the igCombo by the value of the property set by the valueKey.

———————

var jsonData = [
{textValue: "this is dummy data", importantId: 1 },
{textValue: "this is also dummy data", importantId: 2 }
]
$("#checkboxSelectCombo1").igCombo({
width: "270px",
dataSource: jsonData,
textKey: "textValue",
valueKey: "importantId"
});
//Now I need to add code that would select the second item
//("{textValue: "this is also dummy data", importantId: 2}")
//from the igCombo.
//The API suggests that the "select" method
//(http://www.igniteui.com/help/api/2015.2/ui.igcombo#methods:select)
//should be used.
//Neither of these lines work as expected.

$("#checkboxSelectCombo1").igCombo("select", jsonData[1]);
$("#checkboxSelectCombo1").igCombo("select", {importantId: 2});
$("#checkboxSelectCombo1").igCombo("select", 2);

———————


      
Sign In to post a reply

Replies

  • 0
    Thomas Fang
    Thomas Fang answered on May 4, 2016 8:03 PM

    I found the answer after some trial and error. The "value" method (http://www.igniteui.com/help/api/2015.2/ui.igcombo#methods:value) is the one that should be used.

    $("#checkboxSelectCombo1").igCombo("value", 2);

    • 0
      Zdravko Kolev
      Zdravko Kolev answered on May 5, 2016 8:36 AM

      Hello,

      Thank you for your question.

      I am glad that you’ve managed to find the solution. I wanted to add also that there are 2 more ways to select item from the combo list items. Have a look at the code snippet below. I have also uploaded a working sample, I hope you will benefit from it.

      Code snippet:

      $("#singleSelectCombo").igCombo({
                      width: "270px",
                      dataSource: colors,
                      textKey: "Name",
                      valueKey: "Name",
                      dropDownOnFocus: true
                  });
      
                  $("#multiSelectCombo").igCombo({
                      width: "270px",
                      dataSource: colors,
                      textKey: "Name",
                      valueKey: "Name",
                      multiSelection: {
                          enabled: true
                      },
                      initialSelectedItems: [{
                          index: 2
                      }, {
                          index: 4
                      }]
                  });
      
                  $("#checkboxSelectCombo").igCombo({
                      width: "270px",
                      dataSource: colors,
                      textKey: "Name",
                      valueKey: "Name",
                      multiSelection: {
                          enabled: true,
                          showCheckboxes: true
                      }
                  });
      
                  // With 'index' method
                  $("#singleSelectCombo").igCombo("index", 0);
      
                  // With 'value' method
                  $("#multiSelectCombo").igCombo("value", ["White", "Yellow"]);
      
                  //With 'select' method
                  $("#checkboxSelectCombo").igCombo("select",
                      $.makeArray(
                          $("#multiSelectCombo").igCombo("itemsFromIndex", 0).element,
                          $("#multiSelectCombo").igCombo("itemsFromIndex", 1).element
                      ), {}
                  );
      
                  // This is also a valid definition
                  //$("#checkboxSelectCombo").igCombo("select", $("#multiSelectCombo").igCombo("itemsFromIndex", 0).element.add($("#multiSelectCombo").igCombo("itemsFromIndex", 1).element), { });

       

      Attachments:
  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Thomas Fang
Favorites
0
Replies
2
Created On
May 05, 2016
Last Post
9 years, 10 months ago

Suggested Discussions

Tags

Created by

Created on

May 5, 2016 8:36 AM

Last activity on

Feb 23, 2026 11:56 AM