3

I am using angular datatables and I have only one column.

When I bind it, the data comes in an ascneding order, while I want to display it in the order I recived it.

Can someone please help.

Controller :

        var vm = this;
        vm.dtOptions = DTOptionsBuilder.newOptions()
        .withButtons([
            'print',
            'pdfHtml5',

        ]);
        vm.dtColumnDefs = [
            DTColumnDefBuilder.newColumnDef(0).notSortable()
        ];

HTML :

  <div ng-controller="formViewController as frmView">
    <table datatable="ng" dt-options="frmView.dtOptions" dt-column-defs="frmView.dtColumnDefs" class="row-border hover">
        <thead>
            <tr>
                <td>
                    {{Title}}
                </td>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="plugin in newArray track by $index">
                <td>
                    //Content
                </td>
            </tr>
        </tbody>
    </table>
</div>
2

3 Answers 3

13

Look at order, formerly known as aaSorting. Add

.withOption('order', [])

to your dtOptions. The default value of order is [[0, 'asc']], setting it to [] will prevent dataTables from making an initial sort on the first column after initialisation.

Sign up to request clarification or add additional context in comments.

Comments

2

Resolved

this.dtOptions ={
 ajax:{},
 columns:[],
 order:[] //<= Use this
}

This worked for me. I tried several other ways, but thus seems to be the better solution.

Comments

2

Try This

  dtOptions: DataTables.Settings = {};

  ngOnInit() {
    // table settings
    this.dtOptions = {
      pagingType: 'full_numbers',
      pageLength: 10,
      retrieve: true,
      order:[[0, 'desc']]   // '0' is the table column(1st column) and 'desc' is the sorting order
    }
  }

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.