如何在表初始化时禁用排序

时间:2014-11-14 10:59:58

标签: jquery django sorting datatables

我在django项目中使用jquery datatables插件和服务器端处理。

我想显示从mysql数据库到jquery datatable的最新插入记录。目前,当我重新加载页面时,表数据默认按第一列的升序排序。我不想要这个。有没有办法显示在页面加载时从服务器发送的数据?然后在点击列时,应该对相应的列进行排序。我怎样才能做到这一点?有什么帮助吗?

2 个答案:

答案 0 :(得分:0)

使用此功能并尝试:

$(document).ready(function() {
$('#example').dataTable({
    "order": []
});

});

看看这个https://datatables.net/reference/option/order

答案 1 :(得分:0)

    here is sample code to initialize data table plugin 

    var oTable = $('.datatable').dataTable({
                        "sPaginationType": "full_numbers",
                        "bJQueryUI": false,
                        "sDom": '<"H">t<"F"ip>',
                        "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
                        "iDisplayLength": 10,
                        "aaSorting": [[0, 'desc']],
                        "oLanguage": { "oPaginate": { "sNext": '>', "sLast": '>>', "sFirst": '<<', "sPrevious": '<'} }                    
                    });


in above initialization we have to remove "aaSorting" paramater. 


    var oTable = $('.datatable').dataTable({
                        "sPaginationType": "full_numbers",
                        "bJQueryUI": false,
                        "sDom": '<"H">t<"F"ip>',
                        "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
                        "iDisplayLength": 10,
                        "oLanguage": { "oPaginate": { "sNext": '>', "sLast": '>>', "sFirst": '<<', "sPrevious": '<'} }                    
                    });