I am trying to filter the Grid based on what the user types. One of my fields is a drop down list and if the foreignKey ID is null the filter breaks because it cannot get the value.
The field is Gender. Is there a way to first check if Gender_Id is null before I check Gender_Types.Gender? Because if Gender_Id is null then so is Gender_Types.
Here is my code:
// Filter the Grid as a user types
$("#Search").on("keyup click input", function () {
grid = $("#Grid").data("kendoGrid");
var searchFilter = { logic: "and", filters: [] };
if (this.value.length > 0) {
var search = this.value.trim();
var search_array = search.split(" ");
for (var i = 0; i < search_array.length; i++) {
var filter = { logic: "or", filters: [] };
filter.filters.push({ field: "Full_Name", operator: "contains", value: search_array[i] });
filter.filters.push({ field: "Gender_Types.Gender", operator: "contains", value: search_array[i] });
searchFilter.filters.push(filter);
}
grid.dataSource.query({ filter: searchFilter });
// When done filtering select page one otherwise no page is selected
grid.dataSource.page(1);
} else {
grid.dataSource.query({ filter: searchFilter });
// When done filtering select page one otherwise no page is selected
grid.dataSource.page(1);
}
});
The field is Gender. Is there a way to first check if Gender_Id is null before I check Gender_Types.Gender? Because if Gender_Id is null then so is Gender_Types.
Here is my code:
// Filter the Grid as a user types
$("#Search").on("keyup click input", function () {
grid = $("#Grid").data("kendoGrid");
var searchFilter = { logic: "and", filters: [] };
if (this.value.length > 0) {
var search = this.value.trim();
var search_array = search.split(" ");
for (var i = 0; i < search_array.length; i++) {
var filter = { logic: "or", filters: [] };
filter.filters.push({ field: "Full_Name", operator: "contains", value: search_array[i] });
filter.filters.push({ field: "Gender_Types.Gender", operator: "contains", value: search_array[i] });
searchFilter.filters.push(filter);
}
grid.dataSource.query({ filter: searchFilter });
// When done filtering select page one otherwise no page is selected
grid.dataSource.page(1);
} else {
grid.dataSource.query({ filter: searchFilter });
// When done filtering select page one otherwise no page is selected
grid.dataSource.page(1);
}
});