I am trying to show html data using ngTable.
In html, I made all the columns "sorted".
<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 the 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,
count: 10,
}, {
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 shows the entries on 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 will need to apply the values from NgTableParams.sorting () to the data you want to display in your table. This usually happens when the data is retrieved from the server. "However, he did not say how to apply this method to the data Ngtable 1.0.0 seems to be poorly documented and lacking examples. Can someone show me how to sort on client side?