1

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?

1

2 Answers 2

4

Just set the order option :

$scope.dtOptions = DTOptionsBuilder.newOptions()
  .withOption('order', [[0, 'desc']])

Your usage of columnDefs is a little bit wrong. It should be

$scope.dtColumnDefs = [
  DTColumnDefBuilder.newColumnDef(0).withOption('type', 'date').notSortable()
];  
Sign up to request clarification or add additional context in comments.

Comments

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">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.