Table of Contents

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.

No Sorting

Adding bSort: false in option. Example:

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

Sorting According to the First Column, in Ascending Order

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

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

Sorting According to the First Column, in Descending Order

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

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

Sorting for Multiple Columns

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"]]
});