What is the best way to capture and store the chosen text in a Kendo multiselect variable?

I recently transformed the kendo dropdownlist into a kendo multiselect.

The dropdownlist now has 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.

The desired output format for variable MPID should look like this:

(3)["D","UDMS","TMA Data Mgmt System"]
(3)["U","TDMS","SMA Mgmt System"]

Answer №1

To retrieve the selected dataItems from the multiselect, you should utilize the dataItems method.

In order to achieve this, simply update your code snippet from:

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

to:

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

This will provide you with an array of selected dataItems. If you only require the IDs, consider either setting the valuePrimitive property to true or mapping the dataItems accordingly.

I have included a demo link showcasing how to retrieve the items:

The example is adapted from the API demo for multiselects, where I modified the functionality of the Get Values button to specifically map the items to their values and stringify the dataItems array.

Answer №2

To achieve this, you can follow these steps:

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

After performing the above code snippet, the desired output will be obtained.

https://i.sstatic.net/ghKlj.png

Try out the live demonstration here

Answer №3

I found a solution that worked for me:

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

            //// creating an array with only the selected ids
            var IDArray = [];
            $(dataItems).each(function () {
                IDArray.push(this.Name.split('-')); // accessing properties on the model
            });
            console.log(IDArray);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you merge the values between two arrays of objects by counting them and combining them into a single array?

I'm faced with an array conundrum categories: [ { name: 'category1', items: 0, }, { name: 'category2', items: 0, }, { name: 'category3', items: 0, }, ] And then there's this separate ar ...

Converting bullet point list to checkboxes once requirements have been satisfied

I am working on developing a password validator with specific regex conditions in Material UI that transitions from bullet points to checkboxes when the criteria are satisfied. https://i.sstatic.net/b0pgb.png Initially, I attempted to use the npm library ...

Display or conceal a field depending on the user's input

I need to display a checkbox only when the firstname matches abc or if the email is [email protected]. var x = abc; //will be dynamic var y = abc @gmail.com jQuery("#firstname").on('change', (function(avalue) { return function(e) { ...

Avoiding concurrent work on identical rows by users

My workplace has a web application that functions as a ticket system. Some users submit new issues, while others resolve them. All the data is stored in MS SQL Server 2005. Those assigned to resolve issues can access a page to view open cases. Since multi ...

Dealing with errors when working with cross-domain JSONP requests in jQuery can be a

My attempts to capture a bad request error using my jquery code have been unsuccessful. $.get('http://example.com/', {}, function () {}, 'jsonp') .done(function () { // never fires }) .fail(function () { // never fires }) .a ...

Locate the unique identifier of the window responsible for triggering alerts

Can anyone provide a solution for identifying the ID of the Internet Explorer window that triggers alert boxes? I suspect it is related to the document or window itself. This can be achieved using basic HTML or jQuery code. I attempted the following appr ...

Iterating through a JSON object using an API loop

Just starting out in JS and I am attempting to use a for loop to combine all the 'text' from various JSON objects into one cohesive paragraph. For example, it should read like this: "Hello, and welcome to the Minute Physics tutorial on basic Rock ...

Implementation of Exporting to Excel

function fnshowAuditList() { if(auditListTable) auditListTable.fnDestroy(); jQuery.ajax({ type: 'POST', url: 'auditListAction', data: '', dataType: 'text&a ...

What is the optimal method for iterating through every element in a string array?

Within my code, I am dealing with an array named var mya = ["someval1", "someotherval1", "someval2", "someval3"];. The goal is to have a function that receives an object with a property set to one of these values. Instead of simply iterating over the arra ...

The syntax in JavaScript of (0, fn)(args) is used to call

I came across an interesting piece of JavaScript code in Google's codebase that I wanted to discuss: var myVar = function...; (0, myVar)(args); Do you know what the significance of this syntax is? I'm struggling to see the difference between ( ...

Can an open inventor scenegraph be transformed into a threejs scene?

Is there a way to display open inventor scengraph in a webgl format? I'm looking for some suggestions on how to tackle this project. Any ideas are welcome! ...

Learn how to eliminate all text characters from a string using jQuery, leaving only the numerical values behind

My webpage features a variety of different products, each with their own values. When trying to calculate the total sum of these products and display it in the shopping cart, I encountered an error displaying NaN. How can I remove this NaN from the strin ...

Looking for the quickest hash and salt method for IP addresses in Node.JS?

Currently, there are many stipulations regarding the tracking of user data such as unique visits and returning users. An issue arises in certain regions where IP addresses are considered sensitive personal information. To continue identifying unique user ...

Decrease the construction duration within a sprawling Angular 8 project

It takes nearly 10-15 minutes to compile the project in production mode, resulting in a dist folder size of 32MB Here are the production options I am currently using:- "production": { "optimization": true, "outputHashing": "all", ...

Exploring the analysis of JavaScript and CSS coverage throughout various pages or websites

The Chrome Dev Tools JavaScript and CSS Coverage Drawer is quite impressive, but there is one thing that could make it even better. It would be great if it could remain active without restarting its analysis every time you visit a new page. I wish I could ...

Combining HTML, PHP, and Ajax within a single document

Hey everyone! I'm diving back into web programming and challenging myself to create a simple mailing form using just HTML, PHP, and Ajax all within a single file. The goal is to have a self-contained HTML document that doesn't refresh when the fo ...

Easily generate a component directory complete with all essential files in just a few simple clicks

In my work with React and the typical app structure, I utilize a directory called src/components to store all of my React components. I am looking for a way to streamline the process of creating new components. I would like to be able to generate a compon ...

Can Browserify be used with AngularJS to bundle directive templateUrls using relative paths?

Currently, I am developing a web application using AngularJS and Browserify to bundle my JavaScript files into a single package for use on the webpage. My project structure looks something like this: app |-index.html |-index.js |-bundle.js |-components ...

Unable to successfully download zip files using Ajax in the MVC framework

I need to trigger the download of a zip file that contains .pdf files using an ajax call. The issue I'm encountering is that everything seems to be working fine except for the actual downloading of the zip file. public FileResult DownloadZip(string[] ...

Utilize SoundCloud API to generate user profiles according to their unique identification within the system

In my system, I have implemented a process that takes an array of SoundCloud user IDs. These IDs are then iterated through a series of SC.get functions to gather information about each user, such as their user ID, username, followings, and genre preference ...