【问题标题】:datatable default sorting not working数据表默认排序不起作用
【发布时间】:2017-07-25 04:40:19
【问题描述】:

我在我的 rails 应用程序中使用 jquery 数据表。我想将默认顺序添加到特定列。我有下面的jquery代码,

    $(document).ready(function(){
        $('#sample-table-2').DataTable({
            responsive: true,
            "pagingType": "simple",
            bJqueryUI: true,
            bServerSide: true,
      "aaSorting": [[ 4, "asc" ]], // 
            sAjaxSource: $('#sample-table-2').data('source'),
            "columnDefs": [
                { "width": "10%", "targets": column_count }
              ]
        })
        .on( 'order.dt',  function () { eventFired( 'Order' ); } )
        .on('page', function () {setTimeout(function(){hideCellsOnMobile();},1000)} )
        .on( 'search.dt', function () {setTimeout(function(){hideCellsOnMobile();},1000)});
        $("table#sample-table-2").parent().addClass("no-padding")
});

但是这个默认排序没有得到应用。

【问题讨论】:

  • Targets 根据文档需要一个数组,所以你可能想试试{ "width": "10%", "targets": [ column_count] }

标签: jquery ruby-on-rails datatables


【解决方案1】:

你用的是什么版本?你可以试试这个吗?

$(document).ready(function(){
        $('#sample-table-2').DataTable({
            responsive: true,
            "pagingType": "simple",
            bJqueryUI: true,
            bServerSide: true,
            order: [[ 4, "asc" ]], // 
            sAjaxSource: $('#sample-table-2').data('source'),
            "columnDefs": [
                { "width": "10%", "targets": column_count }
              ]
        })
        .on( 'order.dt',  function () { eventFired( 'Order' ); } )
        .on('page', function () {setTimeout(function(){hideCellsOnMobile();},1000)} )
        .on( 'search.dt', function () {setTimeout(function(){hideCellsOnMobile();},1000)});
        $("table#sample-table-2").parent().addClass("no-padding")
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多