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. Image for the cookie policy date

Multiselect datasource based on selected items from other multiselect

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.


1 Reply

VK Vinoth Kumar Sundara Moorthy Syncfusion Team 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 id="city" placeholder="Select a state" popupHeight="@ViewBag.popupHeight" dataSource="@ViewBag.cities"> 
    <e-multiselect-fields text="CityName" value="CityId"></e-multiselect-fields> 
    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; 
    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); 
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? 
Vinoth Kumar S 

Live Chat Icon For mobile
Up arrow icon