I am writing an app using AngularJS on the front end. I want to search through a table by any word/field; one search box for everything. I tried to follow this plunker's working example: http://plnkr.co/edit/aIuSDYlFbC4doW6pfsC9?p=preview
This is my code on the front end:
<div class = "row">
<label>Search: <input ng-model="query"></label>
</div>
<div class = "row">
<table ng-repeat="post in posts | orderBy: sort | filter: search">
<tr>
<td> {{index(post)}} </td>
<td> {{post.title}} </td>
<td> {{post.author}} </td>
<td> {{post.content}} </td>
<td> {{post.date | date: "d/M/yyyy"}} </td>
</tr>
</table>
</div>
And this is inside my main controller:
'use strict';
$scope.posts = posts.posts;
$scope.search = function (row) {
return (angular.lowercase(row.author).indexOf($scope.query || '') !== -1 ||
angular.lowercase(row.title).indexOf($scope.query || '') !== -1 ||
angular.lowercase(row.content).indexOf($scope.query || '') !== -1 ||
angular.lowercase(row.date).indexOf($scope.query || '') !== -1 ||
};
What should I do? Thank you