angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

Default Sort Column

Open greghaar opened this issue 12 years ago • 25 comments

Is it possible to set a default column for initial sorting?

greghaar avatar Jul 19 '14 06:07 greghaar

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']);

l-lin avatar Jul 19 '14 09:07 l-lin

Hi!

I used the code below, but it's not working $scope.dtOptions = DTOptionsBuilder.newOptions() .withOption('order', [1, 'desc']);

heavyrajn avatar Jul 22 '14 23:07 heavyrajn

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

greghaar avatar Jul 23 '14 00:07 greghaar

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

heavyrajn avatar Jul 23 '14 02:07 heavyrajn

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 : image

prateem avatar Jul 23 '14 03:07 prateem

@Prateem Thank for your help . But it's also not working on my project T.T

heavyrajn avatar Jul 23 '14 03:07 heavyrajn

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.

l-lin avatar Jul 23 '14 07:07 l-lin

Thank you!, the key is aaSorting:

DTOptionsBuilder.newOptions().withOption('aaSorting', [3, 'asc'])

osmanhoyos avatar Mar 10 '15 16:03 osmanhoyos

the key order worked for me.

fernyherrera avatar Apr 10 '15 17:04 fernyherrera

thanks l-lin for solution

Jasbindarsingh avatar May 02 '15 09:05 Jasbindarsingh

Thank you!

Hansel03 avatar Oct 29 '15 19:10 Hansel03

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?

enpo avatar Jan 08 '16 13:01 enpo

order expects an array of array:

DTOptionsBuilder.newOptions().withOption('aaSorting', [[3, 'desc']])

l-lin avatar Jan 08 '16 13:01 l-lin

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']])

enpo avatar Jan 08 '16 13:01 enpo

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?

harshamaddineni avatar Feb 24 '16 21:02 harshamaddineni

You need to create your own sorting plugin.

l-lin avatar Feb 24 '16 21:02 l-lin

how to do that lin? Could you help me out

harshamaddineni avatar Feb 24 '16 21:02 harshamaddineni

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.

alecfullofmer avatar Aug 05 '16 22:08 alecfullofmer

For me, DTOptionsBuilder.newOptions().withOption('aaSorting', [3, 'desc']).

Please update the 'order' with 'aaSorting' and it works.

Thanks.

maniempire avatar Aug 12 '16 11:08 maniempire

Hi, I wonder if it is also possible to disable sorting for particular column?

zygimantus avatar Jun 01 '17 18:06 zygimantus