I have a list of dates coming from API and one such date is like "2017-07-05T10:53:24.000Z"
Am displaying dates in first column in datatable. In controller am defining the column like
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).withOption('type', 'date'),
DTColumnDefBuilder.newColumnDef(1).notSortable(),
....
];
HTML
<table datatable="ng" dt-options="dtOptions" dt-column-defs="dtColumnDefs">
<thead>
<tr class="table-header-color-yellow">
<th class="table-head-style">Date</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="review in reviews">
<td>{{review.date | date}}</td>
</tr>
</tbody>
</table>
How can i sort the dates in descending order as it is sorting in ascending order as of now?
答案 0 :(得分:3)
只需设置order
选项:
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('order', [[0, 'desc']])
您对columnDefs
的使用有点不对劲。它应该是
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).withOption('type', 'date').notSortable()
];
答案 1 :(得分:0)
Convert date part into dd/MM/yyyy
Then in controller use
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef([1]).withOption('type', 'date')
];
and Html should be like this
<table class="table table-hover" datatable="ng" dt-column-defs="dtColumnDefs">