Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve sorting status of JQuery Datatables

I'm pretty new to JQuery Datatables,

I'm attempting to retrieve two information about the Datatable

  1. Which column index is currently being sorted (aka selected)
  2. Which order it is being sorted (asc or desc)

not sure how I should approach this (use jquery to find the column index or does Datatables have an API that allows me to retrieve this information.

thanks a lot :D

like image 633
DFIVE Avatar asked Jun 28 '12 19:06

DFIVE


2 Answers

I'm not sure what do you mean by "retrieve", but if you define your datatable like this:

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

You have access to its setting via:

myDataTable.fnSettings();

See also:

  1. http://datatables.net/api#fnSettings
  2. http://datatables.net/docs/DataTables/1.9.0/DataTable.models.oSettings.html

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

myDataTable.fnSettings().aaSorting;

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

like image 95
Tohid Avatar answered Nov 15 '22 22:11

Tohid


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

take a look at api

like image 42
badr slaoui Avatar answered Nov 15 '22 21:11

badr slaoui