0

I am trying to filter an angular-datatable. The search box by default searches all of the values in ng-model and filters the table accordingly.

I need to store the ID of the select list in the database but I want to search by the Name displayed on the list:

 <tbody>
    <tr ng-repeat="waiver in model.waivers | filter:model.searchValue">
        <td><select ng-model="waiver.CarrierID" ng-options="carrier.Key as carrier.Value for carrier in model.Carriers" ng-change="UpdateLists(waiver)"></select></td>
        <td><select ng-model="waiver.CategoryID" ng-options="category.Key as category.Value for category in model.Categories"></select></td>
        //Several more TD's with selectLists etc
    </tr>
</tbody>

When I put 1234 in the search box then It filters to one carrier. What I want to do is put UPS in the box and have it filter to that.

UPDATE:

I have now added The carrier name to the model so waiver.CarrierName has the value I want to search by. I am still unable to get it to narrow the results by that value:

<td style="display:none"><input type="hidden" ng-model="waiver.CarrierName" />

With that it still can't find just the data associated to UPS. If I search any of the non select list values it shrinks the table to the correct data.

Robert
  • 4,306
  • 11
  • 45
  • 95
  • I am unable to understand the requirement. You wish to first search by one attribute and then search by another attribute? That is after narrowing down the results with the first search, you wish to narrow the results down further with another search? – callmekatootie Jul 28 '15 at 15:43
  • @callmekatootie No in its basic state the search box filters by ng-model. Since the model is based on the ID not the Name, it wont search the name. A user doesn't know the ID in the database so they want to search by the name. I need to search by that instead – Robert Jul 28 '15 at 15:44

2 Answers2

0

I think what you are looking at is way to filter by properties if so then yes its possible to filter for a particular property. You can have filter on multiple properties on same object.

<tr ng-repeat="waiver in model.waivers | filter:{CarrierID:model.searchValue,Name:model.searchValue}"></tr>

In the above example you are filtering on a particular property of the model carrierType

Angular Filter

Liam
  • 2,837
  • 23
  • 36
  • That would work if I could get the selected options name assigned to a separate value. Currently I am assigning the ID to the CarrierID value. I cannot assign two values to the model. Unless I missed something – Robert Jul 28 '15 at 17:33
  • You could do {CarrierID:model.searchValue, name:model.searchValue} – Liam Jul 28 '15 at 17:53
  • It would search both ID and name with the value searched by user. The user can search by both ID and name. you can even search by another model value. You could do {CarrierID:model.searchValue, name:model.searchName} – Liam Jul 28 '15 at 18:30
  • Thats not working either. Let me try and refine my question – Robert Jul 28 '15 at 18:37
  • Ok got it - does your waiver object has both name and ID ? Can you update the question with object structure – Liam Jul 28 '15 at 18:46
0

I usually just make my own custom filter for searching. Here is an example of a silly one I wrote for a demo app.

https://github.com/jkrot/clubmanager/blob/master/src/app/index.js

Also here is the filter example from the angular demo.

https://docs.angularjs.org/tutorial/step_09

James
  • 1,514
  • 12
  • 30