在表格中,我想要使用多选下拉列表来过滤行。
这里是plunker。
示例:
当我选择2个国家/地区和2个月的下拉菜单时,数据会相应地显示在表格中。
HTML:
<div id="datatable-buttons_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
<!--page size-->
<div class="table-search-bar">
<div class="dt-buttons btn-group">
PageSize:
<select ng-model="entryLimit" class="form-control">
<option>5</option>
<option>10</option>
<option>20</option>
<option>50</option>
<option>100</option>
</select>
</div>
<!--filter-->
<div id="datatable-buttons_filter" class="dataTables_filter"><label>Filtered:<input type="text" ng-model="search" ng-change="filter()" placeholder="Filter" class="form-control input-sm" aria-controls="datatable-buttons" /></label></div>
</div>
<div ng-show="filteredItems > 0">
<table id="datatable-buttons" class="table table-striped table-bordered">
<thead>
<th> <input type="checkbox" ng-model="selectRowId" ng-click="selectedAll()"></th>
<th>id</th>
<th><a ng-click="sort_by('year');">Year </a></th>
<th><a ng-click="sort_by('month');">Month </a></th>
<th><a ng-click="sort_by('country');">Country </a></th>
<th><a ng-click="sort_by('mobile_operator');">Mobile Operator </a></th>
<th><a ng-click="sort_by('service');">Service </a></th>
<th>Action</th>
</thead>
<tbody ng-init="get_product()">
<tr ng-repeat="product in filtered = (pagedItems| filter:search | orderBy : predicate :reverse) | limitTo:entryLimit ">
<td>
<input type="checkbox" ng-model="selctedIds[product.id]" ng-checked="product.deleted">
</td>
<td>{{ product.id}} </td>
<td>{{ product.year}} </td>
<td>{{ product.month}}</td>
<td>{{ product.country}}</td>
<td>{{ product.mobile_operator}}</td>
<td>{{ product.service}}</td>
<td><a href="" ng-click="prod_update(product.id)">Update</a></td>
</tr>
</tbody>
</table>
<!--total result out of-->
<div class="dataTables_info" id="datatable-buttons_info" >Page {{currentPage + 1}} of {{numberOfPages}} <!--Showing {{ filtered.length}} of {{ totalItems}} entries--></div>
<!--pagination-->
<div ng-show="filteredItems > 0">
<button class="btn" ng-disabled="currentPage <= 0" ng-click="currentPage = currentPage - 1"><<</button>
<!-- <button class="btn" ng-disabled="currentPage == 0" ng-click="currentPage = 0">1</button>
<button class="btn" ng-disabled="currentPage == 1" ng-click="currentPage = 1">2</button>....
<button class="btn" ng-disabled="currentPage == numberOfPages - 1" ng-click="currentPage = numberOfPages - 1">{{numberOfPages - 1}}</button>
<button class="btn" ng-disabled="currentPage == numberOfPages" ng-click="currentPage = numberOfPages">{{numberOfPages}}</button>-->
<button class="btn" ng-disabled="currentPage >= numberOfPages" ng-click="currentPage = currentPage + 1">>></button>
</div>
</div>
<div ng-show="filteredItems == 0">
<div class="col-md-12">
<h4 class="center-margin">No Role found</h4>
</div>
</div>
</div>
我感谢每一个回复。谢谢你。
答案 0 :(得分:4)
New Plunker with your requested implementation
相关守则变更如下。 的控制器:强>
$scope.monthList = [1,2,3,4,5,6,7,8,9,10];
$scope.countryList = ["Chad", "India", "China", "UK"];
$scope.selectedMonths = $scope.monthList;// To show all results initialy, all the options in the countries list will be selected
$scope.selectedCountries = $scope.countryList;// To show all results initialy, all the options in the months list will be selected
&#13;
使用的自定义过滤器:&#39; inArray&#39;
.filter('inArray', function($filter){
return function(list, arrayFilter, element){
if(arrayFilter){
return $filter("filter")(list, function(listItem){
return arrayFilter.indexOf(listItem[element]) != -1;
});
}
};
});
&#13;
各国的多选下拉列表
<select size="4" multiple ng-multiple="true" ng-model="selectedCountries" ng-options="country for country in countryList"></select>
&#13;
<select size="10" multiple ng-multiple="true" ng-model="selectedMonths" ng-options="month for month in monthList"></select>
&#13;
所有代码都是不言自明的。