Default Sort Column
Is it possible to set a default column for initial sorting?
Yes, you can. You need to provide the option order.
For example, ordering the second column descending:
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('order', [1, 'desc']);
Hi!
I used the code below, but it's not working
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('order', [1, 'desc']);
I'll be honest, I actually had difficulty getting it to work too... does this work with the Angular way? That's what I'm using...
Yes, i'm using Angular Way for my project. I used the code above , but i don't know why it's not working as me expect
Try using an aa, so:
$scope.dtOptions = DTOptionsBuilder.newOptions() .withOption('order', [[1, 'desc']]);
Based on this, pulled from https://datatables.net/examples/basic_init/table_sorting.html :

@Prateem Thank for your help . But it's also not working on my project T.T
What version of DataTables are you using? What about the version of angular-datatables? If it's 1.9.4, then the key value for order should be aaSorting and not order (which is for 1.10+).
Here an example that works for DT 1.10+ on Plnkr. Here an another example for DT 1.9.4 on Plnk.
Thank you!, the key is aaSorting:
DTOptionsBuilder.newOptions().withOption('aaSorting', [3, 'asc'])
the key order worked for me.
thanks l-lin for solution
Thank you!
using datatables 1.10.10 with angular datatables 0.5.2, neither DTOptionsBuilder.newOptions().withOption('order', [3, 'desc']) nor DTOptionsBuilder.newOptions().withOption('aaSorting', [3, 'desc']) is working. Can somebody advise?
order expects an array of array:
DTOptionsBuilder.newOptions().withOption('aaSorting', [[3, 'desc']])
thank you, forgot to reference dt-options in my table element. now working with html <table datatable="ng" dt-options="dtOptions">[...]</table> and js $scope.dtOptions = DTOptionsBuilder.newOptions().withOption('aaSorting', [[2, 'desc']])
i have an issue in my project. i am using angular js data tables. while sorting, if i have data for one column as 1.4,1.5,10,2.4 i need to return it as 1.4,1.5,2.4,10. but i am getting as 1.4,1.5,10,2.4. it is considering only first character i suppose.
is there any solution for this?
You need to create your own sorting plugin.
how to do that lin? Could you help me out
Hi Lin, thanks for building this tool.
I am struggling to get my dtOptions object working and therefore struggling to get the order I need. I am using datatables version 1.10.1 the app also has a dependency on angular-datatables v 0.4.3. It's a large maven project. I have tried to replicate your plunker.
My html:
<table datatable="ng" dt-options="dtOptions">
<thead>
<th>DATE</th>
<th>STATUS</th>
<th>FILE</th>
<th>EXPORT</th>'
</thead>
<tr dt-rows ng-repeat="import in recentImports">
<td>{{ import.uploadDate }}</td>
<td>{{ import.status }}</td>
<td><a >{{ import.filename }}</a></td>
<td><a>{{ import.export }}</a></td>
</tr>
</table>
My angular code:
scope.dtOptions = DTOptionsBuilder.newOptions()
.withPaginationType('full_numbers')
.withDisplayLength(2)
.withOption('order', [[0, 'desc']]);
None of the DT options are working. Any ideas? Thanks.
For me, DTOptionsBuilder.newOptions().withOption('aaSorting', [3, 'desc']).
Please update the 'order' with 'aaSorting' and it works.
Thanks.
Hi, I wonder if it is also possible to disable sorting for particular column?