2014-10-30 143 views
0

請解決我的問題。我想要顯示降序。默認情況下它是升序。DataTables排序沒有按降序顯示

請檢查我的代碼 -

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請幫幫我。

回答

1

您必須將order屬性添加到您的表配置中。您的數據表版本不支持order屬性。如果可以,我建議更新到最新版本的數據表。

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

這裏是fiddle。 (注意:我必須註釋掉分頁屬性,取消註釋)