First Column Always Displays Sort Arrow
First Column Always Displays Sort Arrow
tlbaxter99
Posts: 5Questions: 4Answers: 0
Hi, It seems that even though I indicate "orderable": false
, the first column is always displayed with an ascending sort arrow.
I do not want the entire table to be unorderable. Sometimes some columns need to be orderable and other times they don't. Below is a minimal example that illustrates the problem.
The problem I see is that the first column is always sorted even though I have "orderable": false
on every column.
Below is the entire Body of my HTML:
<div id="vitsContainer" style="background-color:antiquewhite">
</div>
<script>
"use strict";
jQuery(document).ready(documentReady);
var dataSet = [
["Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750"],
["Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800"],
];
function documentReady() {
var tableCounter = 0;
var tableElement = document.createElement("table");
tableElement.id = "tbl_" + ++tableCounter;
$("#vitsContainer").append(tableElement);
$("#" + tableElement.id).DataTable({
data: dataSet,
columns: [
{ "title": "Name", "orderable": false },
{ "title": "Position", "orderable": false },
{ "title": "Office", "orderable": false },
{ "title": "Extn.", "orderable": false },
{ "title": "Start date", "orderable": false },
{ "title": "Salary", "orderable": false }
]
});
} // documentReady()
</script>
This discussion has been closed.
Answers
If you want the entire table to not be sortable, set https://datatables.net/reference/option/ordering to false and remove all the column.orderable
It's because it defaults to sort by the first column. Add
to explicitly tell it to order by another column