Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make columns unsortable in dataTables.js jQuery plugin

I am using the dataTables.js jQuery plugin.

The first column of my table is a row counter, so I don't want it be sortable by the user. The last column contains some action link that the user can perform on a row. How can I make these two columns unsortable?

Note: I am using pipeline (server-side process) mode of datatables.

like image 378
hd. Avatar asked Apr 30 '11 06:04

hd.


2 Answers

This is done by setting bSortable to false:

/* Using aoColumnDefs */
$(document).ready(function() {
    $('#example').dataTable( {
        "aoColumnDefs": [ 
            { "bSortable": false, "aTargets": [ 0 ] }
        ] } );
} );

/* Using aoColumns */
$(document).ready(function() {
    $('#example').dataTable( {
        "aoColumns": [ 
            { "bSortable": false },
            null,
            null,
            null,
            null
        ] } );
} );
like image 156
sieppl Avatar answered Sep 19 '22 22:09

sieppl


DataTables 1.10+ also supports HTML5 data- style attributes, including data-sortable="false", which makes the column ineligible for sorting:

<table>
    <thead>
        <tr>
            <th data-sortable="false">Row</th>
            <th>Name</th>
            <th>Join Date</th>
            <th>Organization</th>
            <th data-sortable="false">Options</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            [etc]
        </tr>
    </tbody>
</table>

See this demo in jsFiddle

like image 35
Jeromy French Avatar answered Sep 19 '22 22:09

Jeromy French