Reputation: 703
I am doing a search in my table content, at a particular time I want to filter my table only based on the particular field.
For example, I have a table with number, name and content column. When I enter text in the search box it should search the matched value only in number and name, not the content. How to do this in angular js.
Upvotes: 0
Views: 365
Reputation: 51
You can supply a filter function to your ng-repeat assuming your code is structured like the following,
<table>
<thead>
<th>
<td>Number</td>
<td>Name</td>
<td>Content</td>
</th>
<thead>
<tbody>
<tr ng-repeat="item in ctrl.items | filter : ctrl.filterOnNameAndNumber">
<td>{{item.number}}</td>
<td>{{item.name}}</td>
<td>{{item.content}}</td>
</tr>
</tbody>
</table>
ctrl.filterOnNameAndNumber = function (item) {
// filter logic here
return item.name.indexOf(ctrl.search) > -1 || item.number === ctrl.search;
}
Fore more information, read the following API docs,
https://docs.angularjs.org/api/ng/filter/filter
Upvotes: 1