I have multiple filters working fine over an ng-repeat. However, the code seems unnecessarily long to actually action the filters on a set and I'm wondering if there is a better way.
Here is an example filter - this bit I'm OK with (unless anyone has any advice) - they all follow a similar structure:
app.js
.filter('taskClient', function() {
return function (items, clientId) {
if (!clientId) { return items; }
var filtered = [];
angular.forEach(items, function(item) {
if (item.client) {
if (item.client.id === clientId) {
filtered.push(item);
}
}
});
return filtered;
}
})
And as I said - there are several of these. Then, on my ng-repeat, I implement them as so (this is the bit that seems hard to maintain and overly long and would appreciate info on any better techniques):
tasks-index.html
<md-list-item icp-task-line ng-repeat="task in TasksCtrl.tasks | taskOwner: TasksCtrl.selectedUserFilter | taskClient: TasksCtrl.clientId | taskDepartment: TasksCtrl.departmentId | taskPriority: TasksCtrl.priority | taskWithClient: TasksCtrl.withClient | taskEndDate: TasksCtrl.endDate | filter: {progress: 0} | filter: searchText | orderBy: TasksCtrl.orderTasks" class="md-2-line"></md-list-item>
Judging by how much scroll is involved here, I imagine you can see my issue with the above code. In order to get the length of tasks in view (also separated into completed, in progress etc) I have to list all the filters out again.
Is there a better way to implement these filters?
I'm also concerned that after reading this article I'm not understanding the difference between stateful and nonstateful filters - are the above filters optimised for performance?