How do we get the Selected items TEXT for a multiselect dropdown?

1 Answer 1089 Views
MultiSelect
Neelima
Top achievements
Rank 1
Neelima asked on 24 Oct 2017, 05:15 AM

Hi there,

I have a multi select dropdown. I was able to get the selected items list - which has the list of id's. But I wanted to pull the list of selected items text, instead of id's? Can someone help me out please?

 

Ex: MULTISLECT Dropdown

    Id Value

  1    ABC

  2  XYZ

  3  IJK

If 1 and 2 are selected, I wanted the values [ABC, XYZ], instead of [1,2].

 

Appreciate your help.

 

Kind Regards

NeelimaN

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Oct 2017, 08:41 AM
Hello Neelima,

The MultiSelect's dataItems() method can be used to retrieve a list of the selected data items. You can use them to retrieve the selected text as follows:
<script>
$("#getMultiValues").on("click", function() {
  var multi = $("#products").getKendoMultiSelect(),
     multiDataItems = multi.dataItems(),
     selectedProducts = [];
               
 for(var i = 0; i < multiDataItems.length; i += 1) {
   var currentProduct = multiDataItems[i];
                 
  selectedProducts.push({
   ProductID: currentProduct.ProductID,
   ProductName: currentProduct.ProductName
  })
}
               
console.log(selectedProducts);
});
</script>


You can checkout the following Dojo example, where the above is demonstrated.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Neelima
Top achievements
Rank 1
commented on 26 Oct 2017, 04:42 PM

Hi Dimitar,

Thank you for the reply.

 

I wanted to check if there is any predefined property for this, like I was able to get the selected values. In my case I have 3 dropdowns and each one has so many items binded to it. So, wanted to see if there is way to skip looping through each record.

 

Thanks!

Dimitar
Telerik team
commented on 27 Oct 2017, 04:45 AM

Hеllo Neelima,

The MultiSelect's value() method retrieves the input element value. For example if we set the the ProductID in the dataValueField configuration option, the value() method will return a list of ids. What you can do to skip looping through the dataItems is to set the ProductName in the dataValueField. This way, by using the value() method you will be able to obtain the list of names successfully. Checkout this Dojo example.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Neelima
Top achievements
Rank 1
commented on 27 Oct 2017, 05:50 AM

Thank you so much for the example Dimitar.

Also I found a similar scenario at: https://stackoverflow.com/questions/32638037/angularjs-how-to-filter-ngrepeat-with-another-array-elements

The only issue I had with the above example is, I had to parse the id's to integers (from string)

Many thanks again!

Smita
Top achievements
Rank 1
commented on 04 Nov 2019, 06:46 AM

Thank you, it works

 

Tags
MultiSelect
Asked by
Neelima
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or