2

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

2 Answers 2

12

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

$scope.options = DTOptionsBuilder.newOptions().withOption('order', [[5, 'asc']])
Sign up to request clarification or add additional context in comments.

1 Comment

saved me loads of time
0

You can reorder the array of objects with the javascript function sort

$scope.asc = false;
$scope.reorder = function(direction){
    items.sort(function(a, b) {
      return a.id - b.id;
    });
    if(asc){
        items.reverse();
        asc = false;
    }
}

And add a button with an ng-click calling reorder

<button ng-click="$scope.reorder()">Reorder</button>

Every time you press the Reorder button, your list is going to switch from Asc Order and Desc Order

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.