datatables_sorting

DataTables Sorting

There are two options that control the sorting, and they are bsort and order. Note that the index of columns of the DataTables is start with 0. I.e. The index of the first column is 0.

Adding bSort: false in option. Example:

var table = $("#table").DataTable({
	dom: 'rti',
	pageLength: -1,
	bSort: false
});

Adding order: [[0, "asc"]] in option. Example:

var table = $("#table").DataTable({
	dom: 'rti',
	pageLength: -1,
        order: [[0, "asc"]]
});

Adding order: [[0, "desc"]] in option. Example:

var table = $("#table").DataTable({
	dom: 'rti',
	pageLength: -1,
        order: [[0, "desc"]]
});

order option actually accepts an array of input. If we want to sort the first column in descending order, and second column in ascending order, we can use order: [[0, "desc"], [1, "asc"]] in option. Example:

var table = $("#table").DataTable({
	dom: 'rti',
	pageLength: -1,
        order: [[0, "desc"],
                [1, "asc"]]
});
  • datatables_sorting.txt
  • Last modified: 2018/09/26 10:13
  • by chongtin