How to disable initial Ordering of data in Angular Datatables?

依然范特西╮ 提交于 2020-01-05 04:05:33

问题


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>

回答1:


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.




回答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.



来源:https://stackoverflow.com/questions/40733990/how-to-disable-initial-ordering-of-data-in-angular-datatables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!