<code>
<script>
var communityData;
var countryData;
function communityCascade(args) {
args.requiresDefaultFilter = false; // restrict the inbuilt mapping for cascading dropdown
var predicates = [];
var casVal = args.cascadeValue.split(";");
for (var i = 0; i < casVal.length; i++) {
predicates.push(new ej.Predicate("Code", ej.FilterOperators.equal, casVal[i]));
}
args.cascadeQuery = ej.Query().where(ej.Predicate["or"](predicates));
var CountryInst = $("#Country").ejDropDownList("instance");
if (ej.isNullOrUndefined(this["City"]) && !ej.isNullOrUndefined(CountryInst["City"])) {
this["City"] = CountryInst["City"];
}
else if (ej.isNullOrUndefined(this["City"])) this["City"] = this.selectDropObj.model.dataSource;
var changedSource = ej.DataManager(this["City"]).executeLocal(args.cascadeQuery);
var communityData = [];
if (CountryInst._changedSource && CountryInst._changedSource.length > 0) communityData = communityData.concat(CountryInst._changedSource);
if (this.checkedStatus) {
if (this._changedSource && this._changedSource.length > 0) communityData = this._changedSource.concat(changedSource);
else communityData = communityData.concat(changedSource);
communityData = removeduplicate(communityData);
}
else {
communityData = removeduplicate(communityData);
for (var i = 0; i < changedSource.length; i++) {
for (var j = 0; j < this._changedSource.length; j++) {
if (JSON.stringify(this._changedSource[j]) == JSON.stringify(changedSource[i]))
this._changedSource.splice(j, 1);
}
for (var j = 0; j < CountryInst._changedSource.length; j++) {
if (JSON.stringify(CountryInst._changedSource[j]) == JSON.stringify(changedSource[i]))
CountryInst._changedSource.splice(j, 1);
}
}
communityData = this._changedSource;
communityData = communityData.concat(CountryInst._changedSource);
}
communityData = removeduplicate(communityData);
args.setCascadeModel = { "dataSource": communityData ,"enabled":true};
}
function countryCascade(args) {
args.requiresDefaultFilter = false;
args.cascadeQuery = ej.Query().where("IdCountry", "equal", args.cascadeValue);
var ComunityInst = $("#Comunity").ejDropDownList("instance");
if (ej.isNullOrUndefined(this["City"]) && !ej.isNullOrUndefined(ComunityInst["City"])) {
this["City"] = ComunityInst["City"];
}
else if (ej.isNullOrUndefined(this["City"])) this["City"] = this.selectDropObj.model.dataSource;
var changedSource = ej.DataManager(this["City"]).executeLocal(ej.Query().where("IdCountry", "equal", args.cascadeValue));
var countryData = [];
if (ComunityInst._changedSource && ComunityInst._changedSource.length > 0) countryData = countryData.concat(ComunityInst._changedSource);
if (this.checkedStatus) {
if (this._changedSource && this._changedSource.length > 0) countryData = this._changedSource.concat(changedSource);
else countryData = countryData.concat(changedSource);
countryData = removeduplicate(countryData);
}
else {
countryData = removeduplicate(countryData);
for (var i = 0; i < changedSource.length; i++) {
for (var j = 0; j < this._changedSource.length; j++) {
if (JSON.stringify(this._changedSource[j]) == JSON.stringify(changedSource[i]))
this._changedSource.splice(j, 1);
}
for (var j = 0; j < ComunityInst._changedSource.length; j++) {
if (JSON.stringify(ComunityInst._changedSource[j]) == JSON.stringify(changedSource[i]))
ComunityInst._changedSource.splice(j, 1);
}
}
countryData = this._changedSource;
countryData = countryData.concat(ComunityInst._changedSource);
}
countryData = removeduplicate(countryData);
args.setCascadeModel = { "dataSource": countryData, "enabled": true };
}
function removeduplicate(communityData) {
var uniqueNames = [];
$.each(communityData, function (i, el) {
if ($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
return uniqueNames;
}
</script>
</code> |