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

5 posts, 1 answers
  1. Neelima
    Neelima avatar
    18 posts
    Member since:
    Oct 2017

    Posted 24 Oct 2017 Link to this post

    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

  2. Dimitar
    Admin
    Dimitar avatar
    255 posts

    Posted 25 Oct 2017 Link to this post

    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.
  3. Neelima
    Neelima avatar
    18 posts
    Member since:
    Oct 2017

    Posted 26 Oct 2017 in reply to Dimitar Link to this post

    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!

  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    255 posts

    Posted 26 Oct 2017 Link to this post

    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.
  5. Neelima
    Neelima avatar
    18 posts
    Member since:
    Oct 2017

    Posted 27 Oct 2017 in reply to Dimitar Link to this post

    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!

Back to Top