我想用ngTable在html上顯示數據。ngTable不排序?
在html中,我使所有列都「可排序」。
<table ng-table="fm.tableParams" class="table" show-filter="false">
<tr ng-repeat="report in $data">
<td title="'ReportId'" sortable="'reportId'" class="text-center">
{{report.reportId}}</td>
<td title="'SampleId'" sortable="'sampleId'" class="text-center">
{{report.sampleId}}</td>
<td title="'MRN'" sortable="'mrn'" class="text-center">
{{report.mrn}}</td>
<td title="'Diagnosis'" sortable="'diagnosis'" class="text-center">
{{report.diagnosis}}</td>
</tr>
</table>
從服務器檢索數據。 controller.js
ristoreApp.controller("fmCtrl",
['$scope', 'fmFactory', 'NgTableParams', function($scope, fmFactory, NgTableParams) {
var self = this;
$scope.selection = '0';
$scope.fmSearch = function() {
if ($scope.selection == '0') {
self.tableParams = new NgTableParams({
page: 1, // show first page
count: 10, // count per page
}, {
getData: function (params) {
return fmFactory.getAll().then(function(response) {
var reports = response.data;
params.total(reports.length);
console.log(reports.length);
return reports;
});
}
});
self.tableParams.reload();
}
}
}]
)
它確實顯示頁面中的記錄。但是排序不適用於任何列。我需要做些什麼才能使它工作?
編輯: 據ngtable.com,「你需要從NgTableParams.sorting()申請的值要在表格中顯示的數據,這通常情況下,當數據被取出來自服務器。「但它沒有說如何將這種方法應用於數據。看起來ngtable 1.0.0的記錄很差,缺乏示例。任何人都可以告訴我如何在客戶端排序?
因此,每次點擊網頁上每列的小箭頭,我都會向服務器發送一個請求並獲取具有特定順序的json列表?我所做的從服務器獲取數據是調用rest api。如何通過http請求中的不同列指定不同的順序? – ddd
這很大程度上取決於您定位的其他api。如果api不支持排序,解決此問題的唯一方法是加載所有項目並在客戶端排序項目。 –
這正是我打算做的 - 在客戶端對它們進行分類。我該怎麼做? – ddd