我正在使用搜索框(输入)来过滤表格结果.目前它有关StudentName列的过滤,但它必须是动态的.
让我们说:
filter :{'RollNo' :test} filter :{'Dept' :test}
简而言之:
<input type="text" ng-model="test"> <table> <tr ng-repeat="x in names |filter :{'StudentName' :test}"></tr> </table>
解决方法
按照以下方法 –
要搜索不同的内容,您需要使用不同的输入字段,否则您必须根据您的要求类型创建自定义过滤器
要搜索不同的内容,您需要使用不同的输入字段,否则您必须根据您的要求类型创建自定义过滤器
<label>Any: <input ng-model="search.$"></label> <br> <label>Name only <input ng-model="search.name"></label><br> <label>RollNo only <input ng-model="search.RollNo"></label><br> <table> <tr ng-repeat="x in names | filter:search"> <td>{{x.name}}</td> <td>{{x.RollNo}}</td> </tr> </table>
编辑
这是您的自定义过滤器:
.filter('TableFilter',function(){ return function(dataArray,type,filtervalue) { if (!dataArray) { return; }else{ if(type === 'Name'){ return dataArray.filter(function(item){ var term = item.name === filtervalue; return term; }); }else if(status === 'RollNo'){ return dataArray.filter(function(item){ var term = item.RollNo === filtervalue; return term; }); } } } }); <tr ng-repeat="x in names | TableFilter : dropDownvalue : test">