1

I have converted the kendo dropdownlist into kendo multiselect.

Dropdownlist contains 2 items:

  1. D-UDMS-TMA Data Mgmt System
  2. U-TDMS-SMA Mgmt System
$("#btnSendFlow").click(function () {

            debugger;

            var FlowData_array = [];

            //var ROLECODE = $("#DDRolecode").val().trim();---For dropdownlist output: "D"
            var ROLECODE = $("#DDRolecode").data("kendoMultiSelect").value();//added by chetan for multiselect output: "D" "U"

            // var MPID = $("#DDRolecode").data("kendoDropDownList").text().split('-');---for dropdownlist output: (3)["D","UDMS","TMA Data Mgmt System"]
            var MPID = $("#DDRolecode").data("kendoMultiSelect").value().split('-');//added for multiselect(How to do For multiple selected items?)-->
            output should be like:
            (3)["D","UDMS","TMA Data Mgmt System"]
            (3)["U","TDMS","SMA Mgmt System"]



        .....
        .....
        }

Commented lines is for Dropdownlist.

Output should be like for var MPID:

(3)["D","UDMS","TMA Data Mgmt System"]
(3)["U","TDMS","SMA Mgmt System"]
halfer
  • 19,824
  • 17
  • 99
  • 186
chetan kambli
  • 794
  • 5
  • 21

3 Answers3

3

You need to use the dataItems method on the multiselect to get the underlying selected dataItems.

so all you should need to do is change your code from:

var MPID = $("#DDRolecode").data("kendoMultiSelect").value().split('-') 

to:

var MPID = $("#DDRolecode").data("kendoMultiSelect").dataItems(); 

So this will give you an array of dataItems that you have selected. So if you need to only have the id then either change the value mapping to valuePrimitive:true or map the returning dataItems to the array list you need.

I have included a dojo showing how to get the items: https://dojo.telerik.com/ILEvITUQ

This is taken from the api demo dojo for multiselects but I have changed the Get Values button to map the items to their values only and also stringifying the dataItems array.

David Shorthose
  • 4,489
  • 2
  • 13
  • 12
2

You can do like:

var selectedValues = $("#DDRolecode").data("kendoMultiSelect").value().map(item => item.split("-"));

The result will be:

Console result

Demo

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
  • var ROLECODE = $("#DDRolecode").data("kendoMultiSelect").value(); var MPID = $("#DDRolecode").data("kendoMultiSelect").value().map(item => item.split("-")); – chetan kambli Sep 09 '19 at 13:31
  • @Dintvotedown.. i am getting the multiselect data from Sp. Kindly check the link.. https://stackoverflow.com/questions/57802489/how-to-convert-kendo-dropdownlist-into-kendo-multiselect?noredirect=1#comment102040518_57802489 – chetan kambli Sep 09 '19 at 13:33
  • @chetankambli your output is differente because your data is differente, i think. – DontVoteMeDown Sep 09 '19 at 13:41
  • i am not getting the result in your format..Thats exactly what i want ..i am just getting the value in a array like D and U – chetan kambli Sep 09 '19 at 13:43
  • @chetankambli yeah I see that, but I'm saying based on img you added, that your data is not like you've posted in the question.. look at your data: https://i.stack.imgur.com/78GPn.png – DontVoteMeDown Sep 09 '19 at 13:57
  • i am trying to display the result for the variable MPID – chetan kambli Sep 09 '19 at 14:01
  • 1
    @chetankambli you could simplify your code to `var MPID = control.dataItems().map(item => item.Name.split("-"));` – DontVoteMeDown Sep 10 '19 at 11:56
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/199248/discussion-between-chetan-kambli-and-dontvotemedown). – chetan kambli Sep 10 '19 at 13:14
1

The Below code worked for me:

var control = $("#DDRolecode").data("kendoMultiSelect");
            var selectedDataItems = control.dataItems();

            //// create an array that only contains the selected ids
            var MPID = [];
            $(selectedDataItems).each(function () {
                MPID.push(this.Name.split('-')); // you can access any property on your model here
            });
            console.log(MPID);
chetan kambli
  • 794
  • 5
  • 21