请解决我的问题。我想显示降序排列。默认情况下是升序。
请检查我的代码-
<强> 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
最佳答案
您必须添加 order属性到您的表配置。您的数据表版本不支持 order属性(property)。如果可以的话,我建议您更新到最新版本的数据表。
$('#dataTable').dataTable({
order: [
[0, 'desc']
]
});
这是fiddle 。 (注意:我必须注释掉 paginate 属性,在代码中取消注释)
关于javascript - 数据表排序不按降序显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26653343/