我有一張使用ng-table的頁面,它可以與初始數據一起工作。我有一個選擇框根據選擇的選項發送服務器請求,然後Iam獲取新的數據到角度,但不會用ng-table更新。ng-Table在重新加載請求時沒有呈現新數據
這是我的觀點:
<section data-ng-controller="ReportsController">
<div class="plain-box">
<table ng-table="tableParams" show-filter="true" class="table table-striped">
<thead>
<tr>
<th ng-repeat="column in columns" ng-show="column.visible"
class="text-center sortable" ng-class="{
'sort-asc': tableParams.isSortBy(column.field, 'asc'),
'sort-desc': tableParams.isSortBy(column.field, 'desc')
}"
ng-click="tableParams.sorting(column.field, tableParams.isSortBy(column.field, 'asc') ? 'desc' : 'asc')">
{{column.title}}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in $data">
<td ng-repeat="column in columns" sortable="column.field">
{{user[column.field]}}
</td>
</tr>
</tbody>
</table>
</div>
我的控制器:
angular.module('reports').controller('ReportsController', ['$scope', '$stateParams', '$location', 'Authentication', 'Reports', '$filter', 'ngTableParams',
function($scope, $stateParams, $location, Authentication, Reports, $filter, ngTableParams) {
$scope.reportBillingPeriod = 0;
$scope.$watch('reportBillingPeriod', function(newValue, oldValue) {
$scope.findReportData(newValue);
});
//$scope.reportBillingData = 0;
$scope.findReportData = function(selectedMonth){
var selectedPeriod = selectedMonth;
if(selectedPeriod === null)
selectedPeriod = '0';
$scope.customers_report = Reports.customer_report({
monthReport: selectedPeriod
}, function(result){
var data = result.customers;
$scope.columns = [
{ title: 'Account Name', field: 'accountName', visible: true, filter: { 'name': 'text' } },
{ title: 'Gross Revenue', field: 'planTotalAmount', visible: true }
];
$scope.$watch('result', function() {
$scope.tableParams.settings().$scope = $scope;
$scope.tableParams.reload();
});
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10, // count per page
filter: {
name: 'O' // initial filter
}
}, {
total: data.length, // length of data
getData: function($defer, params) {
var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
//$scope.reportBillingData = new Date();
}
});
});
};
}]);
我移動$手錶findReportData功能之外,則註釋掉'$ scope.tableParams.settings()$範圍= $範圍;'。然後手動分配'page','count','total'和'counts'的值。但仍然無法正常工作。 – palPalani 2014-10-07 09:48:28
ohh,還有一些需要讓它工作,讓我稍後設置plunk,並找出有什麼問題 – 2014-10-07 09:58:10
對於遲到回覆感到抱歉,請檢查plunk在回答中 – 2014-10-08 14:34:14