Proper Syntax for Initializing "Order" Functionality
Proper Syntax for Initializing "Order" Functionality
TH
Posts: 3Questions: 2Answers: 0
I am trying to use the "order" functionality to sort the 9th column in my table by default. When I try to initialize the datatables using the code below, the datatables functionality fails to appear on page load (HTML table is present, though).
I believe I have followed the documentation for "order" correctly. Any obvious problems in my initialization code below?
https://datatables.net/examples/basic_init/table_sorting.html
<!-- Link out for Jquery, which is a dependency for datatables -->
<script
src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<!-- Link out for datatables -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.16/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.4.2/css/buttons.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/buttons/1.4.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/buttons/1.4.2/js/buttons.print.min.js"></script>
<script language="javascript">
$(document).ready( function () {
$('#table_id').DataTable( {
"order": [[10, "desc"]]
dom: 'Bfrtip' ,
buttons: [
'pageLength',
'print'
]
} );
} );
</script>
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You have a syntax error. This can be seen in your browser's console. You need a comma following this line to separate the parameters:
"order": [[10, "desc"]]
To look like this:
"order": [[10, "desc"]],
Kevin
Thanks Kevin. That fixed it. Will check the browser console for these errors next time.