最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to disable initial Ordering of data in Angular Datatables? - Stack Overflow

programmeradmin10浏览0评论

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>

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>
Share Improve this question asked Nov 22, 2016 at 4:51 Devanshi ParikhDevanshi Parikh 2651 gold badge4 silver badges13 bronze badges 2
  • 3 stackoverflow.com/questions/31027497/… – Vinod Louis Commented Nov 22, 2016 at 5:03
  • I already have what they say, I want to disable ordering, i.e. ascending-descending – Devanshi Parikh Commented Nov 22, 2016 at 8:05
Add a comment  | 

3 Answers 3

Reset to default 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.

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.

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
    }
  }
发布评论

评论列表(0)

  1. 暂无评论