使用带有角度属性分页过滤器的变量
Using a variable with angular-utils-pagination filter
我正在使用 https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination 在这里找到的Angular-utils-pagination指令。到目前为止,它按预期工作,但我想做的最后一件事是添加让用户能够选择他们希望过滤结果的项目的哪个属性的功能。
以下是我到目前为止所拥有的。HTML 标记:
<div class="row">
<div class="col-xs-4">
<h3>Current Page: {{ currentPage }}</h3>
<select ng-model="selectedFilter" ng-options="f for f in filterOptions"></select>
</div>
<div class="col-xs-4">
<label for="search">Search:</label>
<input ng-model="q" id="search" class="form-control" placeholder="Filter text">
</div>
<div class="col-xs-4">
<label for="search">items per page:</label>
<input type="number" min="1" max="100" class="form-control" ng-model="pageSize">
</div>
</div>
...
<tr dir-paginate="item in items | filter:{selectedFilter:q} | itemsPerPage: pageSize" current-page="currentPage">
控制器
$scope.currentPage = 1;
$scope.pageSize = 10;
$scope.filterOptions = [
'item','brand','category','gender','size'
];
// Note that items[] is populated on initialisation from the db.
$scope.items = [];
当我对过滤器进行硬编码以按项目过滤时,如下所示,它按预期工作。
<tr dir-paginate="item in items | filter:{item:q} | itemsPerPage: pageSize" current-page="currentPage">
是否可以使属性对变量进行过滤?任何帮助,不胜感激。
谢谢。
所以下面是我最终得到的,效果很好。
html 标记:设置一个下拉框,其中包含所需的筛选器选项,用于在其中键入搜索条件的框。最后是目录分页指令的逻辑。
<div class="row">
<div class="col-xs-3">
<label for="Filter">Search:</label>
<select ng-model="filter" id="Filter" class="form-control" ng-options="f for f in filterOptions"></select>
{{filter}}
</div>
<div class="col-xs-3">
<label for="search">Search On: <em>{{filter}} </em></label>
<input ng-model="search[filter]" id="search" class="form-control" placeholder="Filter text">
</div>
<div class="col-xs-2">
<label for="search">items per page:</label>
<input type="number" min="1" max="100" class="form-control" ng-model="pageSize">
</div>
</div>
...
<tr dir-paginate="item in items | filter:search | itemsPerPage: pageSize" current-page="currentPage">
控制器:从下拉列表中选择筛选器选项时,它会更改在范围内的搜索数组中选择的属性。然后由 dir-paginate 指令引用的是 $scope.search。
$scope.currentPage = 1;
$scope.pageSize = 10;
$scope.search = {item:'', brand:'', category:'', itemId: '', $:''};
$scope.filterOptions = [
'item','itemId','brand','category','gender','size'
];
相关文章:
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 如何通过引用var Using DataTables来进行分页或排序
- 使用CSS或JavaScript计算分页符的数量
- DataTables-创建自定义分页样式(加载更多样式)
- 使用ajax的服务器端分页&jQuery
- 分页:如何用AJAX加载第一个页面
- dataTables-如何自定义分页类型以显示最后一个页码后面的省略号,
- 用于分页的 AngularJS 自定义过滤器
- 将过滤器与分页角度相结合
- 使用带有角度属性分页过滤器的变量
- AngularJs分页中的搜索框过滤器
- 角度结果和分页不会在过滤器上更新
- Angular分页过滤器错误
- 添加分页后在AngularJS中自定义过滤器
- 使用Angularjs过滤器进行分页
- Ng-table, ng-repeat,过滤器只对分页表中的当前页起作用
- 用于angularjs分页的自定义过滤器
- Angular js服务器端过滤器和分页
- telerik radGrid - 在排序/分页/过滤器上保持客户端状态
- EditableGrid - 使用 javascript 显示搜索过滤器和分页