// Initialize Kendo Grid from our table.
$("#TableGrid").kendoGrid({
sortable: true
});
// attache change event for "OS" dropdown
$("#os").change(function () {
applyFilter("OS", $(this).val());
});
// attach change event to the "network" dropdown.
$("#network").change(function () {
applyFilter("Network", $(this).val());
});
// attach click event for Clear Filters button
$("#clear").click(function () {
clearFilters();
});
// applyFilter function accepts the Field Name and the new value to use for filter.
function applyFilter(filterField, filterValue) {
// get the kendoGrid element.
var gridData = $("#TableGrid").data("kendoGrid");
// get currently applied filters from the Grid.
var currFilterObj = gridData.dataSource.filter();
// get current set of filters, which is supposed to be array.
// if the oject we obtained above is null/undefined, set this to an empty array
var currentFilters = currFilterObj ? currFilterObj.filters : [];
// iterate over current filters array. if a filter for "filterField" is already
// defined, remove it from the array
// once an entry is removed, we stop looking at the rest of the array.
if (currentFilters && currentFilters.length > 0) {
for (var i = 0; i < currentFilters.length; i++) {
if (currentFilters[i].field == filterField) {
currentFilters.splice(i, 1);
break;
}
}
}
// if "filterValue" is "0", meaning "-- select --" option is selected, we don't
// do any further processing. That will be equivalent of removing the filter.
// if a filterValue is selected, we add a new object to the currentFilters array.
if (filterValue != "0") {
currentFilters.push({
field: filterField,
operator: "eq",
value: filterValue
});
}
// finally, the currentFilters array is applied back to the Grid, using "and" logic.
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.