I am trying to add a custom filter to angular-DataTables with server side processing, which works perfectly with sorting and built in search of datatables.<
Ok sorry its not a full blown example. This only works with angular and datatables, if you do a filter on the When these change they kick off the filter routine eg in the in the Hope its of some use. I've avoided boolean variables as they have given grief before. Odd occasions have needed an in your controller, keeps the sorting columns correct. might also be useful if its recalcitrant. I need to know how to make it work for breeze??? Enjoy..ng-repeat eg | aFilter:this
The this
transfers the scope. The filtering applied can now be quite complex. Within the ng-controller
ng-model
value.
aFilter
an angular.filter('aFilter'....
js routine. The records are piped through the afilter routine allowing the ones wanted to be pushed onto an array and this is what is returned with the return. It doesn't work with breeze, yet. Be aware it is unlikely to be server side. To deal with server side maybe an SQL call in the service....another day.ng-table id="test"
:
{{edRec.enCode}} etc
aFilter
, the fltEnCode
represents the ng-model
values, the test variable allows freedom from nulls causing issues upon comparison, good idea to test for undefined first: app.filter('aFilter', [function () {
return function (items, $scope) {
var countItems = 0;
var filtered = [];
var isOK = 0;
angular.forEach(items, function (item) {
isOK = 1;
// some conditions
if ($scope.fltEnCode !== "") {
if (item.enCode === null) { test = ""; } else { test = item.enCode; }
if (test.indexOf($scope.fltEnCode) < 0) isOK = 0;
}
// end of conditions
if (isOK > 0) {
filtered.push(item);
countItems++;
}
});
// alert(countItems);
return filtered;
};
}]);
ng-change
in the html items pointing to an angular function resetting the data by calling the getTheItemsForTest()
in the controller. This redraws the list. Having $scope.dtOptions = {
stateSave: false, .......
$(document).ready(function() {
var table = $('#test').DataTable();
table.draw();
};