在 AngularJS 个数据表中按降序显示日期
Display date in descending order in AngularJS datatables
我有一份来自 API 的日期列表,其中一个日期类似于“2017-07-05T10:53:24.000Z”
我在数据表的第一列中显示日期。在控制器中定义像
这样的列
$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>
我现在如何按升序对日期进行降序排序?
将日期部分转换为dd/MM/yyyy
然后在控制器中使用
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef([1]).withOption('type', 'date')
];
和Html应该是这样的
<table class="table table-hover" datatable="ng" dt-column-defs="dtColumnDefs">
只需设置 order
选项:
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('order', [[0, 'desc']])
您对 columnDefs
的用法有点不对。应该是
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).withOption('type', 'date').notSortable()
];
我有一份来自 API 的日期列表,其中一个日期类似于“2017-07-05T10:53:24.000Z”
我在数据表的第一列中显示日期。在控制器中定义像
这样的列$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>
我现在如何按升序对日期进行降序排序?
将日期部分转换为dd/MM/yyyy
然后在控制器中使用
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef([1]).withOption('type', 'date')
];
和Html应该是这样的
<table class="table table-hover" datatable="ng" dt-column-defs="dtColumnDefs">
只需设置 order
选项:
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('order', [[0, 'desc']])
您对 columnDefs
的用法有点不对。应该是
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).withOption('type', 'date').notSortable()
];