摘要:ngGrid 前端分頁
//js
app.controller('adm020wController', function($scope, adm020wService, $modal, $compile, cAlerter, cResource) {
var mainColumn = [];
$scope.mainColumn = {};
var mainData = [];
$scope.mainData = {};
var upData = [];
cResource().uploadFile({
url: 'rest/fileUpload?size='
+ $scope.pagingOptions.pageSize +'&page='+ $scope.pagingOptions.currentPage,
data: {catalog: $scope.compCatalog, compType: $scope.compType},
file: $file
}).success(function(data, status, headers, config) {
mainData = [];
$scope.mainData = {};
$scope.totalServerItems = data.data.numberOfElements;
upData = data.data;
for(var i=0;i<data.data.size;i++) {
mainData.push(data.data.content[i].map);
}
});
};
$scope.itemGrid = {
data : 'mainData',
columnDefs : 'mainColumn',
enableColumnResize: true,
multiSelect: false,
enablePaging: true,
pagingOptions: $scope.pagingOptions,
currentMaxPages: $scope.currentMaxPages,
totalServerItems: 'totalServerItems',
showFooter: true
};
$scope.setPagingData = function(data, page, pageSize){
mainData = [];
$scope.mainData = [];
var endNum = 0;
if (data.numberOfElements < (page * pageSize)) {
endNum = data.numberOfElements;
} else {
endNum = page * pageSize
}
if (data.length != 0) {
for(var i=((page - 1) * pageSize) ; i< endNum ; i++) {
mainData.push(data.content[i].map);
}
}
$scope.mainData = angular.copy(mainData);
$scope.totalServerItems = data.numberOfElements;
if (!$scope.$$phase) {
$scope.$apply();
}
};
$scope.getPagedDataAsync = function(pageSize, page) {
$scope.setPagingData(upData,page,pageSize);
};
$scope.$watch('pagingOptions', function () {
$scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage);
}, true);
$scope.pagingOptions = {
pageSizes: [10, 20, 50, 100],
pageSize: 10,
totalServerItems: 0,
currentPage: 1
};
//JAVA
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
public Page<DynaBean> fileUpload(@RequestParam("file") MultipartFile multipartFile,
String catalog, String compType, Alerter alerter, Pageable pageable) throws IOException {
log.info("pageNum =" + pageable.getPageNumber());
log.info("pagesize =" + pageable.getPageSize());
}
PageRequest pagereq = new PageRequest(pageable.getPageNumber(), pageable.getPageSize());
Page<DynaBean> topicsPage = new PageImpl<DynaBean>(resultList, pagereq, 0);
List<DynaBean> resultList = new ArrayList<DynaBean>();
try
{
in = new FileReader(file);
Iterable<CSVRecord> records = CSVFormat.EXCEL.withHeader(FILE_HEADER_MAPPING).parse(in);
for (CSVRecord record : records) {
DynaBean compBean = new LazyDynaBean();
for (AdmResourceTypeProperty property : properties) {
compBean.set(property.getResourcePropertyName(), value);
}
resultList.add(compBean);
}
}
}
////WebMvcConfigurerAdapter
spring boot-> application.java
@Override
public void addArgumentResolvers(
List<HandlerMethodArgumentResolver> argumentResolvers) {
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
resolver.setFallbackPageable(new PageRequest(0, 10));
argumentResolvers.add(resolver);
super.addArgumentResolvers(argumentResolvers);
}