Disable sorting for a particular column in jQuery DataTables

前端 未结 23 1615
礼貌的吻别
礼貌的吻别 2020-11-30 19:58

I am using the jQuery DataTables plugin to sort the table fields. My question is: how do I disable sorting for a particular column? I have tried with the following code, but

23条回答
  •  鱼传尺愫
    2020-11-30 20:34

    Using Datatables 1.9.4 I've disabled the sorting for the first column with this code:

    /* Table initialisation */
    $(document).ready(function() {
        $('#rules').dataTable({
            "sDom" : "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
            "sPaginationType" : "bootstrap",
            "oLanguage" : {
                "sLengthMenu" : "_MENU_ records per page"
            },
            // Disable sorting on the first column
            "aoColumnDefs" : [ {
                'bSortable' : false,
                'aTargets' : [ 0 ]
            } ]
        });
    });
    

    EDIT:

    You can disable even by using the no-sort class on your ,

    and use this initialization code:

    // Disable sorting on the no-sort class
    "aoColumnDefs" : [ {
        "bSortable" : false,
        "aTargets" : [ "no-sort" ]
    } ]
    

    EDIT 2

    In this example I'm using Datables with Bootstrap, following an old blog post. Now there is one link with updated material about styling Datatables with bootstrap.

提交回复
热议问题