Benjamin Li Benjamin Li -5 years ago 157
AngularJS Question

angular filter is not working on table if I only input one letter

This is the way how I do filter on a table

<tr ng-repeat="row in | filter: searchTable">

and the
is ng-modeled to an input.

<input type="text" class="form-control" placeholder="SEARCH INVOICES" ng-model="searchTable">
is an array of objects. one of the objects is

{"customerWatched":false,"invoiceID":"00c9511b-24b9-4190-a90a-8abf2fe9f4a0","amountDue":"0.00","referenceNumber":"O721-001","amount":"35.75","contact":{"watched":false,"contactName":"Net Connect","contactId":"bym568b799d81934d3","errorMessage":"","redirectURL":null}

it has more than 100 objects in the array, so cannot list them all.

Unfortunately, if I input one letter, the table does not change anything. But if I input two letters or more, then it works.

what would be the reason?

update: the whole object is too large that I only display part of object in the table. and when I input some letters, it would even search on the hidden part of the object. how to filter on the displayed items of the object only?

Answer Source

Angular's filter filter looks in the whole object for your searchTable value.

All strings or objects with string properties in array that match this string will be returned. This also applies to nested object properties.

When you put only one letter, it probably don't change the table because this letter is present in at least one attribute of each line of

If you prefer, you can filter on a specific attribute of your array (for example invoiceID):

<tr ng-repeat="row in | filter: {invoiceID: searchTable}">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download