AngularJS中的排序、过滤和分页
Sorting,Filtering and Pagination in AngularJS
我是mean stack的新手,第一次用AngularJS编写代码,我试图在下面的index.html文件中实现排序、分页和过滤。我试图实现的方式有些不正确,请帮助这是我的index.html文件-
<!DOCTYPE>
<html ng-app="myApp">
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<title>eAPI Test Execution Portal</title>
</head>
<body>
<div class="container" ng-controller="AppCtrl">
<h1>eAPI Test Execution Portal</h1>
<table class="table table-fluid">
<thead>
<tr>
<th><a href="" ng-click="orderByField='runId'; reverseSort = !reverseSort">runId</a>
<th><a href="" ng-click="orderByField='apiName'; reverseSort = !reverseSort">apiName</a>
</th>
</th>
<th><a href="" ng-click="orderByField='runTime'; reverseSort = !reverseSort">runTime</a>
</th>
<th><a href="" ng-click="orderByField='Report'; reverseSort = !reverseSort">Report</a>
</th>
<th><a href="" ng-click="orderByField='numOfTestExecuted'; reverseSort = !reverseSort">numOfTestExecuted</a>
</th>
<th><a href="" ng-click="orderByField='numOfTestFailed'; reverseSort = !reverseSort">numOfTestFailed</a>
</th>
<th><a href="" ng-click="orderByField='status'; reverseSort = !reverseSort">status</a>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" ng-model="search.runId" placeholder="Search by runId" />
</td>
<td>
<input type="text" ng-model="search.apiName" placeholder="Search by apiName" />
</td>
<td>
<input type="text" ng-model="search.runTime" placeholder="Search by runTime" />
</td>
<td>
<input type="url" ng-model="search.Report" placeholder="Search by Report URL" />
</td>
<td>
<input type="text" ng-model="search.numOfTestExecuted" placeholder="Search by numOfTestExecuted" />
</td>
<td>
<input type="text" ng-model="search.numOfTestFailed" placeholder="Search by numOfTestFailed" />
</td>
<td>
<input type="text" ng-model="search.status" placeholder="Search by status" />
</td>
</tr>
<tr ng-repeat="contact in contactlist">
<td>{{contact.runId}}</td>
<td>{{contact.apiName}}</td>
<td>{{contact.runTime}}</td>
<td>{{contact.Report}}</td>
<td>{{contact.numOfTestExecuted}}</td>
<td>{{contact.numOfTestFailed}}</td>
<td>{{contact.status}}</td>
</tr>
<tr ng-repeat="contact in contactlist | orderBy:predicate:reverse | filter:paginate| filter:search" ng-class-odd="'odd'">
<td>{{user.runId}}</td>
<td>{{user.apiName}}</td>
</tr>
</tbody>
</table>
<pagination total-items="totalItems" ng-model="currentPage" max-size="5" boundary-links="true" items-per-page="numPerPage" class="pagination-sm">
</pagination>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js"></script>
<script src="controllers/controller.js"></script>
</body>
</html>
这是controller.js文件-(如果你想在本地尝试,使用平均堆栈)
var myApp = angular.module('myApp', []);
myApp.controller('AppCtrl', ['$scope', '$http',
function($scope, $http) {
console.log("Hello World from controller");
var refresh = function() {
$http.get('/contactlist').success(function(response) {
console.log("I got the data I requested");
$scope.contactlist = response;
$scope.contact = "";
});
};
refresh();
$scope.addContact = function() {
console.log($scope.contact);
$http.post('/contactlist', $scope.contact).success(function(response) {
console.log(response);
refresh();
});
};
$scope.remove = function(id) {
console.log(id);
$http.delete('/contactlist/' + id).success(function(response) {
refresh();
});
};
$scope.edit = function(id) {
console.log(id);
$http.get('/contactlist/' + id).success(function(response) {
$scope.contact = response;
});
};
$scope.update = function() {
console.log($scope.contact._id);
$http.put('/contactlist/' + $scope.contact._id, $scope.contact).success(function(response) {
refresh();
})
};
$scope.deselect = function() {
$scope.contact = "";
}
}
]);
您可以使用它在本地Mongo-中插入数据
db.contactlist.insert({"runId" : "1212","apiName" : "transactions","runTime" : "DateAndTime","Report" : "URL","numOfTestExecuted" : "3","numOfTestFailed" : "3","status" : "Passed"})
如果你能告诉我你的例子中有什么不起作用,那就太酷了,也许最好把你的问题深入到三个问题中:
排序、分页和筛选。
为每一个都创建一个例子,并尝试实现它,然后直接问什么不起作用。
->因为每个问题都可以独立解决,这样你就更容易理解空穴是如何协同工作的。
你可以为你的每个问题创建一个独立的指令。
相关文章:
- 在部分视图内渲染的WebGrid将引发“;“jQuery未定义”,当尝试执行基于ajax的分页或过滤时
- 分页和过滤在 AngularJS 中不稳定
- vueJs 分页和过滤
- 角度.js分页过滤的数据并显示总项目,而无需在视图/控制器中复制代码
- jqGrid使用JsonString JsonReader实现服务器端排序分页过滤
- 我想添加过滤,分页到myTable
- 在Rails中使用dataTables或过滤并分页
- 如何在ExtJS 5中使用分页过滤网格数据
- AngularJS中的排序、过滤和分页
- 使用Jquery/AJAX/Javascript搜索、排序、分页和过滤DIV
- 如何在过滤后改变数组变量——Angular Ui分页
- 过滤收集后,后网分页器不工作
- 动态Angular表没有分页过滤
- 带分页的复合过滤
- 对过滤行进行分页 — 重置原始数据集 — jQuery 数据表
- Javascript在数据表过滤或分页之后不工作
- 通过ajax获取分页页面的内容,对其进行过滤并将其附加到当前页面
- 过滤后更新AngularJS中的分页
- 当使用jsonrest和分页时,在Gridx中进行客户端过滤
- 排序,搜索(过滤),分页HTML表