我正在努力使代码正确,我很久以前使用过ngTable而且忘了我是如何让它工作的。 Json回归正常。但是什么都没有通过ngTable。
var data = CustomerGet.query().then(function (data) {
$scope.customerArray = data;
}, function (reason) {
errorMngrSvc.handleError(reason);
});
//Customer Employee Table
$scope.tableParams = new ngTableParams({
count: data.length // hides pager
}, {
counts: [], // hides page sizes
groupBy: 'role',
total: data.length,
getData: function ($defer, params) {
var orderedData = params.sorting() ?
$filter('orderBy')(data, $scope.tableParams.orderBy()) :
data;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
查看
<table ng-table="tableParams" class="table">
<tbody ng-repeat="group in $groups">
<tr class="ng-table-group">
<td colspan="{{$columns.length}}">
<a href="" ng-click="group.$hideRows = !group.$hideRows">
<span class="glyphicon" ng-class="{ 'glyphicon-chevron-right': group.$hideRows, 'glyphicon-chevron-down': !group.$hideRows }"></span>
<strong>{{ group.value }}</strong>
</a>
</td>
</tr>
<tr ng-hide="group.$hideRows" ng-repeat="user in group.data">
<td sortable="name" data-title="'Name'">
{{user.CustomerEmployees.CustomerEmployeeFirstName}}
</tr>
</tbody>
</table>
更新
CustomerEmployeeGet.query()
.success(function (data, status) {
$scope.customerArray = data;
$scope.tableParams = new ngTableParams({
count: customerArray.length // hides pager
}, {
counts: [], // hides page sizes
groupBy: 'Role',
total: customerArray.length,
getData: function ($defer, params) {
var orderedData = params.sorting() ?
$filter('orderBy')(customerArray, $scope.tableParams.orderBy()) :
customerArray;;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});
我正在取得一些进展。 错误
TypeError:undefined不是函数 那是在.success线
答案 0 :(得分:0)
我跳过了我的http工厂并从控制器做了所有事情
//Get CustomerEmployees
$http.get('/api/apiCustomerEmployee')
.success(function (data, status) {
$scope.tableParams = new ngTableParams({
count: data.length // hides pager
}, {
counts: [], // hides page sizes
groupBy: 'Role',
total: data.length,
getData: function ($defer, params) {
var orderedData = params.sorting() ?
$filter('orderBy')(data, $scope.tableParams.orderBy()) :
data;;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});