如果您将enablePaging
的{{1}}选项设置为ng-grid
,则启用服务器端分页。
客户端一个怎么样?我在文档中找不到任何暗示,但我无法想象true
也不支持客户端分页。
任何提示?
答案 0 :(得分:6)
我认为角度页面(http://angular-ui.github.io/ng-grid/)上给出的示例实际上显示了客户端分页的示例。如果您查看示例脚本(http://angular-ui.github.io/ng-grid/jsonFiles/largeLoad.json)正在调用的数据负载,您将看到它实际上没有进行任何服务器端分页...它将作为一个大文件发送。
答案 1 :(得分:0)
它可能对你有所帮助!!
AngularJs代码示例
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope, $http) {
$scope.filterOptions = {
filterText: ""
};
$scope.pagingOptions = {
pageSizes: [25, 50, 100],
pageSize: 25,
totalServerItems: 0,
currentPage: 1
};
$scope.setPagingData = function(data, page, pageSize) {
var pagedData = data.slice((page - 1) * pageSize, page * pageSize);
$scope.myData = pagedData;
$scope.pagingOptions.totalServerItems = data.length;
if (!$scope.$$phase) {
$scope.$apply();
}
};
$scope.getPagedDataAsync = function(pageSize, page) {
setTimeout(function() {
$http.get('json').success(function(largeLoad) {
$scope.setPagingData(largeLoad, page, pageSize);
});
}, 100);
};
$scope.$watch('pagingOptions', function() {
$scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
}, true);
$scope.gridOptions = {
data: 'myData',
enablePaging: true,
pagingOptions: $scope.pagingOptions,
showFooter: true
};
$scope.gridOptions.columnDefs = 'gridColumnDefs';
// city loc pop state
$scope.gridColumnDefs = [{
field: "city"
},
{
field: "state"
}, {
field: "pop"
}, {
field: "loc"
}
];
});
HTML code-sample
<div ng-app="myApp" ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="gridOptions"></div>
</div>