Created
May 21, 2013 19:43
-
-
Save rootty/5622611 to your computer and use it in GitHub Desktop.
Kendo UI onColumnFiltering hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mainProjectListGrid = $("#MainProjectsGrid").kendoGrid({........}).data("kendoGrid"); | |
if (mainProjectListGrid.dataSource.originalFilter == undefined) { | |
mainProjectListGrid.dataSource.originalFilter = mainProjectListGrid.dataSource.filter; | |
mainProjectListGrid.dataSource.filter = function () { | |
if (arguments.length > 0) { | |
this.trigger("mpfiltering", arguments); | |
} | |
var result = mainProjectListGrid.dataSource.originalFilter.apply(this, arguments); | |
return result; | |
}; | |
} | |
$("#MainProjectsGrid").data("kendoGrid").dataSource.bind("mpfiltering", function (e) { | |
if (e.sender._filter != undefined) { | |
_updateColumnFilterStatus("MainProjectsGrid", e.sender._filter.filters); | |
} else if (e.sender._filter == undefined && !!e['0']) { | |
_updateColumnFilterStatus("MainProjectsGrid", e['0']['filters']); | |
} | |
}); | |
}; | |
var _updateColumnFilterStatus = function (tableId, filters) { | |
var grid = {}; | |
if (typeof(tableId) === "object") { | |
grid = tableId; | |
} else if (typeof(tableId) === "string") { | |
grid = $("#" + tableId); | |
} | |
$("th a.k-link", grid).removeClass("filter-active"); | |
for (var i = 0; i < filters.length; i++) { | |
$('tr:first th[data-field="' + filters[i].field + '"] a:last', grid).addClass("filter-active"); | |
} | |
}; | |
var _setColumnFilterOnSubProjects = function (e) { | |
var grid = $('div.k-grid', e.detailRow); | |
var kendoGrid = $('div.k-grid', e.detailRow).data("kendoGrid"); | |
if (kendoGrid.dataSource.originalFilter == undefined) { | |
kendoGrid.dataSource.originalFilter = kendoGrid.dataSource.filter; | |
kendoGrid.dataSource.filter = function () { | |
if (arguments.length > 0) { | |
this.trigger("columnFiltering", arguments); | |
} | |
var result = kendoGrid.dataSource.originalFilter.apply(this, arguments); | |
return result; | |
}; | |
} | |
_onColumnFiltering(grid, kendoGrid); | |
}; | |
var _onColumnFiltering = function(grid, kendoGrid) { | |
kendoGrid.dataSource.bind("columnFiltering", function (e) { | |
if (e.sender._filter != undefined) { | |
_updateColumnFilterStatus(grid, e.sender._filter.filters); | |
} else if (e.sender._filter == undefined && !!e['0']) { | |
_updateColumnFilterStatus(grid, e['0']['filters']); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment