leora
leora

Reputation: 196499

Using jQuery datatables, how can I only have the first column be sortable?

I am using the jQuery datatables plugin to add search, paging, etc. to my HTML table and it works great. I have a situation where only the first column should be sortable. I see a lot of posts on the web about how to disable a specific column, but I don't see the opposite (disable sorting on all columns except one).

Is there a syntax to tell datatables to only allow the first column to be sortable and not allow any of the other columns to be sortable (don't show the up down arrow, etc.)?

Upvotes: 0

Views: 94

Answers (1)

RRR
RRR

Reputation: 1084

Kindly check a working demo here.

Add a class no-sort to th for THs for which you don’t want to sort. Then use the following jQuery code:

$(document).ready(function() {
    $('#example').DataTable({

        "aoColumnDefs" : [ {
            "bSortable" : false,
            "aTargets" : [ "no-sort" ]
        } ]
    });
} );

Upvotes: 1

Related Questions