In the below code we have seen how to paginate the table and here we will see custom filter
Custom filter is used to filter each values.
<tr dir-paginate="record in records | orderBy:sortType:sortReverse | filter: 'myFilter' |itemsPerPage:5"></tr>
app.filter('myFilter', function ($filter) {
return function (results, filters) {
if (filters == null) {
return results;
}
var filteredData;
filteredData = $filter('filter')(results, function (record) {
var matchId = false, matchName = false, matchCountry = false, matchSalary = false, matchAge = false;
if (filters.Id != null && filters.Id.length > 0) { matchId = record.Id == filters.Id; } else { matchId = true; }
if (filters.Name != null && filters.Name.length > 0) { matchName = record.Name.toUpperCase().indexOf(filters.Name.toUpperCase()) > -1; } else { matchName = true; }
if (filters.Country != null && filters.Country.length > 0) { matchCountry = record.Country.toString().toUpperCase().indexOf(filters.Country.toString().toUpperCase()) > -1; } else { matchCountry = true; }
//if(filters.caseId != null && filters.caseId.length > 0){ matchCaseId = patient.caseId==filters.caseId;}else{ matchCaseId = true; }
if (filters.Salary != null && filters.Salary.length > 0) { matchSalary = record.Salary.toUpperCase().indexOf(filters.Salary.toUpperCase()) > -1; } else { matchSalary = true; }
if (filters.Age != null && filters.Age.length > 0) { matchAge = record.Age == filters.Age; } else { matchAge = true; }
return matchId && matchName && matchCountry && matchSalary && matchAge;
});
return filteredData;
};
});