Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort column in angular 'datatables'

I created table

<table class="table table-striped table-bordered table-hover" width="100%" datatable="ng" dt-options="options">
<thead>
<tr>
    <th> Nannie ID</th>
    <th> Name</th>
    <th> Last name</th>
    <th> Email</th>
</tr>
</thead>
<tbody>
<tr class="" ng-repeat='item in items'>
    <td><a ui-sref="admin.nanniesEdit({id:item.id})">id{{item.id}}</a></td>
    <td>{{item.profile.name}}</td>
    <td>{{item.lastname}}</td>
    <td>{{item.profile.email}}</td>
</tr>
</tbody>

Table loaded with first column order:

NannieID
id1 
id10    
id12    
id13    
id2 
id3 
id5 

I want get correct order for each click reorder, and when first loading. Expected result:

NannieID
id1 
id2 
id3 
id5 
id10    
id12    
id13    

I added this code, but it helped only when table is loading, after click for reorder column, I got wrong order

$scope.options = DTOptionsBuilder.newOptions().withOption('aaSorting', [[5, 'asc']])

Please, help me

like image 690
Likn Markn Avatar asked May 29 '26 02:05

Likn Markn


1 Answers

Change the aaSorting to order. Your code will be like:

$scope.options = DTOptionsBuilder.newOptions().withOption('order', [[5, 'asc']])
like image 78
rafaelncarvalho Avatar answered May 31 '26 07:05

rafaelncarvalho