user3122648
user3122648

Reputation: 917

Angular search in a table

I want to make a search on the column SN in a table.

there many information in my table, I want to be able to search based on SN but when I add the filter it does not even load my table

This is what I did: in My controler my List is filled :

 $scope.List = {};


 MyServices.getList()
.success(function (data) {
    angular.forEach(data, function (value, index) {
            $scope.List[value.SN] = {
                Description: value.Description,
                SN: value.SN
            }
    });
})
.error(function (error) {
    $scope.status = 'Unable to load customer data: ' + error.message;
});

and this is my HTML:

<label>Search: <input ng-model="search.SN"></label>
<tr ng-repeat="V in List| filter:search">
    <td>{{V.SN}}</td>
    <td>{{V.Description}}</td>
</tr>

Upvotes: 3

Views: 10795

Answers (2)

Nijas Nizam
Nijas Nizam

Reputation: 161

Remove the object declaration on the input field. It will match the whole object for your specified value on the input field:

<label>Search: <input ng-model="search"></label>
<tr ng-repeat="V in List| filter: search">
  <td>{{V.SN}}</td>
  <td>{{V.Description}}</td>
</tr>

Upvotes: 0

vaqifrv
vaqifrv

Reputation: 784

You must write as follow:

   <label>Search: <input ng-model="search.SN"></label>
    <tr ng-repeat="V in List| filter: {SN: search.SN}">
    <td>{{V.SN}}</td>
    <td>{{V.Description}}</td>
    </tr>

Upvotes: 2

Related Questions