<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> |