i have page with ng-table which works fine with initial data. I have a select box which send server request based on the option selected and then Iam getting new data to angular but is not updated with ng-table.
Here is my view:
<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>
My controller:
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();
}
});
});
};
}]);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…