Click here to Skip to main content
14,733,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have 2 input field, and I want to filter the table against the 2 input fields using OR instead of And.

However I'm unable to do it with the code below, the table return all field regardless what I type in the input, anyone can help me with it?
<script type="text/javascript">
 function checking($scope) { 
 $scope.check = function(tableField,input) { 
 if (input.type == "or"){
 if (tableField.name.indexOf(input.name) > -1 || input.name == null || tableField.created_by.indexOf(input.createdby) > -1 || input.createdby == null ){
 return true
 }
 else{
 return false
 }
 }
 } 
 }
</script>

<table ng-table="table">
 <tbody>
 <tr ng-repeat="car in cars" ng-controller="checking" ng-show="check(car,externalFilters)">
 <td data-title="'Name'">
 {{car.name}}
 </td>
 <td data-title="'Created by'">
 {{ car.created_by || 'unknown' }}
 </td>
 </tr>
 </tbody>
</table> 


What I have tried:

I have tried removing input.name == null and input.createdby == null, and it works, however on load no data will be shown, as the script return false.
Posted
v2
Comments
Sinisa Hajnal 9-Jun-16 4:05am
   
Remove input.name == null as you said so the filtering works. Just handle the loading procedure separately. You could check for values immediately upon entering the fuction and return true if its still loading or have separate variable to check.

Why do you have both quotes and single quotes in data-attributes? You missed semi-colon after return true and return false.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900