【问题标题】:DataTables sorting not showing in descending order数据表排序未按降序显示
【发布时间】:2014-10-30 12:44:55
【问题描述】:

请解决我的问题。我想显示降序。默认是升序。

请检查我的代码-

datTable.js

JS-

<script href="http://myshowcam.com/TestSite/assets/data-tables/jquery.dataTables.js"></script>
<script>
$('#dataTable').dataTable({
        "sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "_MENU_ records per page",
            "oPaginate": {
                "sPrevious": "Prev",
                "sNext": "Next"
            }
        },
        "aoColumnDefs": [{
            'bSortable': false,
            'aTargets': [0]
        }]
    });
</script>

HTML-

<table class="table table-striped border-top" id="dataTable">
  <thead>
    <tr>
      <th class="hidden-phone"> #ID </th>
      <th class="hidden-phone"> Username </th>
   </tr>
  </thead>
  <tbody>
    <tr>
      <td>7</td>
      <td>chinu</td>
    </tr>
    <tr>
      <td>3</td>
      <td>Debakanta</td>
    </tr>
    <tr>
      <td>8</td>
      <td>Sanjib</td>
    </tr>
 </tbody>
</table>

默认情况下,我在第一列中获得asc 记录。

我想自定义上面的代码。需要desc

【问题讨论】:

    标签: javascript jquery datatable


    【解决方案1】:

    您必须将order 属性添加到您的表配置中。您的数据表版本不支持 order 属性。如果可以的话,我建议您更新到最新版本的数据表。

    $('#dataTable').dataTable({
        order: [
            [0, 'desc']
        ]
    });
    

    这里是fiddle。 (注意:我不得不注释掉 paginate 属性,在你的代码中取消注释)

    【讨论】:

      【解决方案2】:
      $('#example').DataTable( {
         "aaSorting": [[ 0, "desc" ]] // Sort by first column descending
      } );
      

      http://live.datatables.net/pacirato/1/edit

      【讨论】:

      • 在提供解决方案时,您应该解释为什么这会起作用或创建另一个 sn-p 提供它如何适合问题的代码。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      相关资源
      最近更新 更多