gpt4 book ai didi

javascript - Angular 搜索过滤器不在整个表中搜索

转载 作者:行者123 更新时间:2023-11-30 07:38:03 28 4
gpt4 key购买 nike

问题是搜索过滤器只从当前页面中查找记录,而我希望它从整个表中查找记录。我该怎么做?

<input type="text" placeholder="Search By Any..." ng-model="search.$"/>
<table dir="ltr" width="477" border="1" class="table table-striped table-bordered">
<thead>
<tr>
<th><a style="font-size: 16px;" href="#" ng-click="changeSort('name')">User</a></th>
<th><a style="font-size: 16px;" href="#" ng-click="changeSort('contentType')">Content Type</a></th>
<th><a style="font-size: 16px;" href="#" ng-click="changeSort('contentName')">Content Name</a></th>
<th><a style="font-size: 16px;" href="#" ng-click="changeSort('startTime')">Start Time</a></th>
<th><a style="font-size: 16px;" href="#" ng-click="changeSort('endTime')">End Time</a></th>
<th><a style="font-size: 16px;" href="#" ng-click="changeSort('duration')">Duration(In Secs)</a></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in filteredRecords | filter: search | orderBy:sort:reverse track by $index">
<td>{{record.user}}</td>
<td>{{record.contentType}}</td>
<td>{{record.contentName}}</td>
<td>{{record.startTime}}</td>
<td>{{record.endTime}}</td>
<td>{{record.duration}}</td>
</tr>
</tbody>
</table>
<pagination class="pull-right" style="cursor: pointer;" num-pages="numPages()" current-page="currentPage" on-select-page="pageChanged(page)"></pagination>

Angular 代码:

angular.module("contentViewStatusApp")
.controller("contentViewStatusController", function($scope, contentViewStatusService){
$scope.records = contentViewStatusService.list();
$scope.currentPage = 1
$scope.numPerPage = 10
$scope.maxSize = 5;
$scope.numPages = function(){
return Math.ceil($scope.records.length / $scope.numPerPage);
};
$scope.changeSort = function(value){
if ($scope.sort == value){
$scope.reverse = !$scope.reverse;
return;
}
$scope.sort = value;
$scope.reverse = false;
}
$scope.$watch('currentPage + numPerPage', function(){
var begin = (($scope.currentPage - 1) * $scope.numPerPage), end = begin + $scope.numPerPage;
$scope.filteredRecords = $scope.records.slice(begin, end);
});
});

最佳答案

您可以使用过滤器而不是创建另一个数组来进行分页。这样它将在被过滤之前搜索整个数组。

This page展示了一个带过滤器的分页示例。

然后您可以先进行搜索查询,它应该搜索整个数组。

更新

Here's一个带有根据搜索文本更新的分页。

它监视搜索文本并在过滤后更新页面范围:

$scope.$watch('searchText.name', function (v) {
$scope.currentPage = 0;
$scope.pages = $scope.range();
});

然后根据筛选结果更新pageCount:

$scope.pageCount = function () {
var pages = $filter('filter')($scope.items, $scope.searchText);
return Math.ceil(pages.length / $scope.itemsPerPage);
};

关于javascript - Angular 搜索过滤器不在整个表中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26191205/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com