0

I write Django app, where I have a base.html template and I defined var table where I declared order by column 0 with 'desc' (look below) So I currently use it some templates, where I extend base.html. But now I need to sort in new template firstly by the second column, and after that by the first column (like this: "order": [1, 0, 'desc'] ). I don't know how I modify this variable without a duplicate code. Could somebody help me?

var table = $('#example').dataTable( {
  "columnDefs": [ {
      "targets": 0,
      "searchable": false,
      "order": [0, 'desc'],
      "ordering": true,
    } ]
} );

In template which extends 'base.html'

<script> 
     //modify order method
</script>

1 Answer 1

2

You can set the ordering using .order() then redraw the table:

table.order( [ 1, 'desc' ], [ 0, 'desc' ] ).draw();
Sign up to request clarification or add additional context in comments.

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.