I am trying to show data on html using ngTable.
In html, I made all columns "sortable".
<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>
Data is retrieved from server. 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();
}
}
}]
)
It does show records in the page. However sorting does not work for any of the columns. What do I need to do to make it work?
EDIT: According to ngtable.com, "you'll need to apply the values from NgTableParams.sorting() to the data you want to display in your table. This is typically the case when the data is being fetched from the server." However it didn't say how to apply this method to data. It seems ngtable 1.0.0 is poorly documented and lacks examples. Can anyone show me how to sort at client side?