How to get jQuery Datatables sort status

I'm new to jQuery datatables,

I am trying to get two information about datatable

  • Which column index is currently sorted (selected)
  • Which order is sorted (ascending or descending)

I don't know how I should do this (use jquery to find the column index or Datatables has an API that allows me to get this information.

Thanks a lot: D

+8
jquery dom html css datatables
source share
2 answers

I'm not sure what you mean by "retrieve", but if you define your datatable as follows:

 myDataTable = $('#my-table').dataTable({ . . . }); 

You have access to configure it with:

 myDataTable.fnSettings(); 

See also:

For example, to get an array of columns of sorted columns, try:

 myDataTable.fnSettings().aaSorting; 

http://datatables.net/docs/DataTables/1.9.0/DataTable.models.oSettings.html#aaSorting

+13
source share

The order () method returns an array of arrays containing the sorting of the index and direction.

take a look at the api

+1
source share

All Articles