6

I have a table. I want to filter the table depending on which value is choosen in an select box. The comparison value is {{pipe.pipe_id}} in the select box and {{dimension.pipe_id}} in the table. Guess there's a simple solution for this? Any suggestion?

Pipe:
    <select  id="select01">
        <option ng-repeat="pipe in pipes">{{pipe.code}} - {{pipe.title_en}}</option>
    </select>  


    <table class="table table-striped">
        <thead>
            <tr>
                <th>Pipe</th>
                <th>Size</th>
                <th>Inner diameter</th>
                <th>Outer diameter</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="dimension in dimensions" >
                <td>{{dimension.pipe_id}}</td>
                <td>{{dimension.nominalsize}}</td>
                <td>{{dimension.innerdiameter}}</td>
                <td>{{dimension.outerdiameter}}</td>
            </tr>
        </tbody>
    </table>
1

2 Answers 2

9

I would recommend using the ng-filter.

This link is a simple example using a to-do list. jsfiddle using ng-filter

You will need to bind whatever input you are using with ng-model="varname"

The ng-filter defaults to all fields in the array. It can be filtered to a single column or point to a function in your controller.

Search Field

<select ng-model="searchparam">
   <option value="1">One</option>
   <option value="2">Two</option>
</select>

To Search a single column

<select ng-model="searchparam.columnOne">
   <option value="1">One</option>
   <option value="2">Two</option>
</select>

Repeated Section
(the filter model stays the same even when your input specifies a specific column)

<tr ng-repeat="dimension in dimensions | filter: searchparam">
     <td>{{dimension.columnOne}}</td>
     <td>{{dimension.columnTwo}}</td>
</tr>
Sign up to request clarification or add additional context in comments.

Comments

1

I think you're looking for ng-filter and the filter filter : http://docs.angularjs.org/api/ng.filter:filter

Comments

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.