1

enter image description herei am trying to filter my table data based on the input text, but some how it's not working. Kindly help please.

  <div class="panel panel-default">
   <div class="panel-heading">search
    <input type="text" ng-model="search_text">
    Searching for :: {{search_text}}
   </div>  
  <Table>   
  <table class="table table-hover table-bordered">
    <tr>
        <td>Item ID</td>
        <td>Quantity</td>       
    </tr>
    <tr ng-repeat="item in items | filter:search_text">
        <td>{{item.item[0] }}</td>
        <td>{{item.item[1] }}</td>
    </tr>
 </table>
 </div>
7
  • can you please show us the object (items) ,, Commented Jul 17, 2015 at 12:19
  • Please show us how your data is structured. Commented Jul 17, 2015 at 12:22
  • any errors in console ? Your code seems to be correct Commented Jul 17, 2015 at 12:24
  • have added my Data structure, above ( using firebase ) and there is no error in console Commented Jul 17, 2015 at 12:25
  • What is "not working"? Commented Jul 17, 2015 at 12:28

2 Answers 2

1

Please check for the version your angularjs you are using or any errors in console.

Your code seems to work and is correct indeed.

  //array of items containing itemID and its quantity
  $scope.items = [{
                    item:['chair',45]
                  },
                  {
                    item:['bed',23]
                  },
                  {
                    item:['laptop',8]
                  }]

Here's the working plunkr

The table data is indeed filtering with respect to value you enter in textbox

Sign up to request clarification or add additional context in comments.

Comments

0

Since Angular 1.1.3 you can use:

<tr ng-repeat="item in items | filter:{item[0]: search_text}">

This will compare it to the object property item[0] in your object. If you want the exact match, you can set the filtering to true by adding:

<tr ng-repeat="item in items | filter:{item[0]: search_text}:true">

1 Comment

Actually when i updated my angular version from 1.3 to 1.4.3 version it's throwing error as " Error: [filter:notarray] Expected array but received: {"-JuQxmosAMBeQitsYevP":{"item":["chair","5"]},"-JuQxoG04-WFcrLR5D6G":{"item":["Bed","10"]},"-JuQxrGLi8O8vZjyQ87O":{"item":["Laptop","2"]},"$id":"items","$priority":null}" ... so how can i save my data as array in firebase ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.