【发布时间】:2015-02-02 19:44:46
【问题描述】:
我有一个计算函数,当调用它时,它会获取几个值并使用它们来填充一个 ng-table 的结果。一切正常,除了表应该分页一次只显示 10 个值。而是一次显示所有值。在页面底部,出现了下一步和后退按钮,用于在表格的值之间进行切换。下面是我正在使用的 angularjs 代码。我不确定问题出在哪里。
$scope.tableParams = new ngTableParams({
page: 1, //show first page
count: 10 //conunt per page
},{
total: $scope.subsidyPaymentScheduleTable.length,
getData: function($defer, params){
$defer.resolve($scope.subsidyPaymentScheduleTable.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
//populates the Subsidy table
$scope.populateSubsidyTable = function(monthlySubsidyRedAm, startingSubsidy, monthsOnSubsidy)
{
var currentSubsidy = 0;
var currentDate = $scope.startingDate;
var subsidyDate = new Date();
var monthsLeft = monthsOnSubsidy
$scope.subsidyPaymentScheduleTable = [];
var subsidyPaymentScheduleArray = [];
if(startingSubsidy > 1)
{
currentSubsidy = startingSubsidy;
}
if(monthlySubsidyRedAm <=0)
{
totalAmount = currentSubsidy * 6;
}
else
{
//the first month
$scope.subsidyPaymentScheduleTable.push({
subsidyDate: currentDate,
subsidyAmount: currentSubsidy
});
$scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy;
//the first 5 months after the first
for(i=2; i <= 6; i++)
{
currentDate = moment(currentDate).add(1,'months').format("MM/DD/YYYY");
$scope.subsidyPaymentScheduleTable.push({
subsidyDate: currentDate,
subsidyAmount: currentSubsidy
});
monthsLeft = monthsOnSubsidy - 6;
$scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy;
}
//the rest of the subsidies
while(monthsOnSubsidy > 0)
{
if((currentSubsidy - monthlySubsidyRedAm) > 1)
{
currentSubsidy = currentSubsidy - monthlySubsidyRedAm;
currentDate = moment(currentDate).add(1,'months').format("MM/DD/YYYY");
$scope.subsidyPaymentScheduleTable.push({
subsidyDate: currentDate,
subsidyAmount: currentSubsidy
});
$scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy;
monthsLeft--;
}
else
{
break;
}
}
//reload subsidy table
$scope.tableParams.total($scope.subsidyPaymentScheduleTable.length);
$scope.tableParams.reload();
}
}
这是html代码
<table ng-table="tableParams" class="table subsidyPaymentScheduleTable">
<tr data-ng-repeat="subsidy in subsidyPaymentScheduleTable" class="clickableRow">
<td data-title="'Date'">
{{subsidy.subsidyDate}}
</td>
<td data-title="'Amount'">
{{subsidy.subsidyAmount | currency:"$"}}
</td>
</tr>
</table>
【问题讨论】:
标签: angularjs pagination ngtable