我想從表中使用ngTable填充REST web服務中的數據。 顯示數據,但它們既不可排序也不可過濾。過濾總是返回空列表。AngularJS:與json數據ngTable:篩選和排序不起作用
下面是我引用的API鏈接:http://bazalt-cms.com/ng-table/
JS:
$scope.dataInstances = [];
$scope.getDataInstances = function() {
$http({
method : 'GET',
url : '/rest/v1/data/instances',
headers : {
"Authorization" : "Basic " + btoa("USERNAME" + ":" + "PASSWORD")
},
})
.success(function(data, status) {
$scope.dataInstances = data;
$scope.tableParams.reload();
// just some logging
console.log(JSON.stringify(data));
})
.error(function(data, status) {
alert("Error: " + status);
});
};
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10, // count per page
filter: {
},
sorting: {
date: 'asc' // initial sorting
}
},
{
total: $scope.dataInstances.length, // length of data
getData: function($defer, params) {
// use build-in angular filter
var filteredData = params.filter() ?
$filter('filter')($scope.dataInstances, params.filter()) :
$scope.dataInstances;
var orderedData = params.sorting() ?
$filter('orderBy')(filteredData, params.orderBy()) :
$scope.dataInstances;
params.total(orderedData.length); // set total for recalc pagination
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
HTML:
<div ng-controller="myController" ng-init="getDataInstances()">
<table ng-table="tableParams" show-filter="true" class="table table-condensed">
<tr ng-repeat="dataInstance in dataInstances">
<td data-title="'Name'" sortable="'name'" filter="{ 'name' : 'text'}">{{dataInstance.name}}</td>
<td data-title="'Date'" sortable="'date'" filter="{ 'date' : 'text'}">{{dataInstance.date | date:'dd.MM.yyyy HH:mm' }}</td>
<td data-title="'Type'" sortable="'type'" filter="{ 'type' : 'text'}">{{dataInstance.type}}</td>
</tr>
</table>
</div>
您有任何提示如何得到這個加工?提前
- asynchronously populating an AngularJS ngTable with json data
- Loading JSON via AJAX with NgTable parameters
- Sorting ngTable doesn't work when heading gets clicked
感謝:喜歡 - 嘗試了不同的其他可能的解決方案 - 而且沒有工作!
編輯:http://plnkr.co/edit/1Rp9szNtw8T3GtwpNaZG?p=preview
正在過濾和排序'type'和'name'列的工作嗎? – 2014-10-11 06:33:46
不,一般不起作用。 – Second2None 2014-10-11 09:54:32
plunk將會在這裏有用,你可以設置它嗎? – 2014-10-11 09:58:27