花了很多时间,我无法理解为什么ui grid在整个表中填充数组的最后一个对象。
$scope.gridOptions = {
rowHeight:50,
paginationPageSizes: 0,
paginationPageSize: 5
//paginationCurrentPage: 2
};
function pageNumberOrPageSizeChanged(pageNumber, pageSize)
{
console.log("Received: pageNumber=" + pageNumber + ", pageSize= " + pageSize);
$scope.totalPages= $scope.lengthArray/pageSize ;
if($scope.totalPages==pageNumber){
$scope.pageNumber=$scope.pageNumber+1 ;
$scope.Userdata();
console.log($scope.gridOptions.data);
$scope.gridApiUsed.core.notifyDataChange(uiGridConstants.dataChange.ALL);
}
else{
$scope.pageNumber=$scope.pageNumber;
}
}
$scope.gridOptions.onRegisterApi = function (gridApi) {
$scope.gridApiUsed = gridApi;
console.log($scope.gridApiUsed);
$scope.gridApiUsed.pagination.on.paginationChanged($scope, function (pageNumber, pageSize)
{
pageNumberOrPageSizeChanged(pageNumber, pageSize);
//$scope.$apply();
});
console.log("Current page: " + $scope.gridApiUsed.pagination.getPage());
console.log("index: " + $scope.gridApiUsed.pagination.getTotalPages());
console.log("Page size: " + $scope.gridOptions.paginationPageSize);
}
$scope.gridOptions.data = "myData";
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = true;
$scope.gridOptions.enableGridMenu = false;
$scope.gridOptions.showGridFooter = true;
$scope.gridOptions.showColumnFooter = true;
//$scope.gridOptions.useExternalPagination=true;
$scope.gridOptions.rowIdentity = function(data) {
return data.id;
};
$scope.gridOptions.getRowIdentity = function(data) {
return data.id;
};
$scope.gridOptions.columnDefs = [
{ name:'_id', width:150,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{COL_FIELD}}</span></div>'},
{ name:'account_title', width:150, enableCellEdit: false, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{COL_FIELD}}</span></div>'},
{ name:'email', width:150, enableCellEdit: false, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{COL_FIELD}}</span></div>' },
{ name:'dateCreated', width:150, enableCellEdit: false, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{COL_FIELD}}</span></div>' },
{ name:'action',width:150, enableCellEdit: false, enableFiltering:false, cellTemplate: '<div class="ui-grid-cell-contents"><button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="right" ng-click="grid.appScope.open(row)" style=" display: block;margin: auto;width: 100px;">Open</button></div>' },
{ name:'Approve',width:150, enableCellEdit: false, enableFiltering:false, cellTemplate: '<div class="ui-grid-cell-contents"><button type="button" class="btn btn-default approveGrid" data-container="body" data-toggle="popover" data-placement="right" ng-click="grid.appScope.open(row)" >Approve</button></div>' },
{ name:'Discard',width:150, enableCellEdit: false, enableFiltering:false, cellTemplate: '<div class="ui-grid-cell-contents"><button type="button" class="btn btn-default DiscardGrid" data-container="body" data-toggle="popover" data-placement="right" ng-click="grid.appScope.open(row)">Discard</button></div>' },
];
我正在通过$ scope.Userdata()更新对象的myData数组;功能
所以基本上它检查页面号。当它是最后一页时,它从服务器获取下一批结果并更新myData模型。但在更新时,它会使用array的最后一个对象填充所有行。我没有机会清理代码,对不起
答案 0 :(得分:1)
$scope.gridOptions.rowIdentity = function(data) {
return data.id;
};
行身份正在弄乱我通过服务器动态设置的id。现在工作得很好。谢谢。 :)