We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Multiselect datasource based on selected items from other multiselect

Thread ID:

Created:

Updated:

Platform:

Replies:

146487 Aug 6,2019 06:42 AM UTC Aug 6,2019 12:51 PM UTC ASP.NET Core - EJ 2 1
loading
Tags: MultiSelect Dropdown
Jesse
Asked On August 6, 2019 06:42 AM UTC

I have two multiselect controls on one page.

They both have the same data source.

But I would like the values available in the second control to be only the values selected in the first.


Thanks

Vinoth Kumar Sundara Moorthy [Syncfusion]
Replied On August 6, 2019 12:51 PM UTC

Hi Jesse, 
 
Good day to you. 
 
We have checked your requirement and prepared the sample with dual MultiSelect component. The second dropdown have dataSource value which is based on the selected value from first dropdowns. Please check the below code snippet, 
 
 Code Example 
<ejs-multiselect id="country" placeholder="Select a country" change="onChange" dataSource="@ViewBag.cities"> 
    <e-multiselect-fields text="CityName" value="CityId"></e-multiselect-fields> 
</ejs-multiselect> 
<ejs-multiselect id="city" placeholder="Select a state" popupHeight="@ViewBag.popupHeight" dataSource="@ViewBag.cities"> 
    <e-multiselect-fields text="CityName" value="CityId"></e-multiselect-fields> 
</ejs-multiselect> 
 
<script> 
    var predicates = []; 
 
    function onChange() { 
        var country = document.getElementById('country').ej2_instances[0]; 
        var city = document.getElementById('city').ej2_instances[0]; 
        var tempQuery = getQueryForVal(country.value, city); 
        city.query = tempQuery; 
        city.dataBind(); 
    } 
 
    function getQueryForVal(valuecheck, mulObj) { 
        var predicate 
        var field = !(mulObj.fields.value) ? mulObj.fields.text : mulObj.fields.value; 
        for (var i = 0; i < valuecheck.length; i++) { 
            if (i === 0) { 
                predicate = new ej.data.Predicate(field, 'equal', (valuecheck[i])); 
            } else { 
                predicate = predicate.or(field, 'equal', (valuecheck[i])); 
            } 
        } 
        return new ej.data.Query().where(predicate); 
    } 
</script> 
 
 
In the below sample, the multiselect component allows multiple item selection and the selected value is returned as array. So, you can use predicate generated and update the dataSource to other multiselect component. 
 
 
Could you please check the above details and get back to us if you need any further assistance on this? 
 
Regards, 
Vinoth Kumar S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon