javascript - Searching particular fields using AngularJS -
i have read angularjs documentation pertaining filters here find difficult understand. have list of airlines, including airline name, airline country, , flag indicate whether airline deleted. without filter rows being displayed expected.
i need search on 3 fields , have inputs (yes using bootstrap):
<div class="row"> <div class="col-sm-2" style="text-align: right"> <label for="airport-name-search" class="control-label">airline name</label> </div> <div class="col-sm-2"> <input ng-model="search.airlinenamesearch" type="text" class="form-control input-sm" id="airport-name-search"/> </div> <div class="col-sm-2" style="text-align: right"> <label for="country-name-search" class="control-label">country name</label> </div> <div class="col-sm-2"> <input ng-model="search.countryname" type="text" class="form-control input-sm" id="country-name-search"/> </div> <div class="col-sm-2" style="text-align: right"> <label for="include-deleted-search" class="control-label">include deleted</label> </div> <div class="col-sm-2"> <input ng-model="search.includedeleted" type="checkbox" id="include-deleted-search"/> </div> </div>
my table looks this:
<table class="table table-hover table-striped table-bordered"> <thead> <tr> <th>ariline id</th> <th>airline name</th> <th>country</th> <th>telephone</th> <th>24hr telephone</th> <th>email address</th> <th>deleted</th> </tr> </thead> <tr dir-paginate="airline in airlines | filter:search | itemsperpage: pagesize" current-page="currentpage"> <td>{{ airline.airlineid }}</td> <td>{{ airline.airlinename }}</td> <td>{{ airline.country }}</td> <td>{{ airline.telephonenumber }}</td> <td>{{ ariline.telephone24hour }}</td> <td>{{ airline.emailaddress }}</td> <td>{{ airline.isdeleted }}</td> </tr> </table>
i understand custom filters cannot accept arrays of objects (well that's read anyway; maybe things have changed). struggling construct inline filter search these 3 fields, , don't think have write custom filter. current attempt @ filter looks this:
ng-repeat="airline in airlines | filter:search | itemsperpage: pagesize"
can point me in right direction?
update
i have had success creating filter, this:
<tr dir-paginate="airline in airlines | filter: { airlinename: search.airlinename } | filter: { country: search.countryname } | filter: { isdeleted: search.includedeleted } | itemsperpage: pagesize" current-page="currentpage"><!--- ... ---> </tr>
but problem remaining filter fails if search input empty when page first loads. works fine once criteria added , deleted (blanked). how can correct this?
i have found answer. google friend.
i need replace:
filter: { airlinename: search.airlinename }
with
filter: { airlinename: search.airlinename||'' }
works treat. full post here.
Comments
Post a Comment