Datatables supports HTML5 data- * attributes for this function.
It supports multiple columns in sort order (based on 0)
<table data-order="[[ 1, 'desc' ], [2, 'asc' ]]"> <thead> <tr> <td>First</td> <td>Another column</td> <td>A third</td> </tr> </thead> <tbody> <tr> <td>z</td> <td>1</td> <td>$%^&*</td> </tr> <tr> <td>y</td> <td>2</td> <td>*$%^&</td> </tr> </tbody> </table>
Now my jQuery is just $('table').DataTables();
, and I get my second and third columns sorted in desc / asc order.
Here are some other nice attributes for <table>
that I reuse:
data-page-length="-1"
sets the page length for All (pass 25 for page length 25) ...
data-fixed-header="true"
... Make an assumption
th3byrdm4n Sep 28 '16 at 0:25 2016-09-28 00:25
source share