我正在为我的表使用JQuery数据表但是我希望最后一个条目首先出现在表中,以降序显示。尝试更改PHP MYSQL select语句但不起作用。我想,这可能是根据我的需求安排的代码吗?我是这样,任何一个人都引导我如何做同样的事情?谢谢......
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" >
$(document).ready(function() {
var dataTable = $('#employee-grid').DataTable( {
"processing": true,
"serverSide": true,
"ajax":{
url :"employee-grid-data.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
} );
} );
</script>
答案 0 :(得分:1)
<script type="text/javascript" language="javascript" >
$(document).ready(function() {
var dataTable = $('#employee-grid').DataTable( {
"processing": true,
"serverSide": true,
"order": [[ 0, "desc" ]], //add this line
"ajax":{
url :"employee-grid-data.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
} );
} );
</script>
N.B:假设你的第一列表是某种自动递增的id
答案 1 :(得分:0)
我认为你应该试试这个: -
$(document).ready(function(){
$('#employee-grid').DataTable({
"order": [[ 1, "desc" ]]
});
});
如需了解更多信息,请访问以下链接: - https://datatables.net/examples/basic_init/table_sorting.html
答案 2 :(得分:0)
您需要指定默认订单列,如下所示:
var dataTable = $('#employee-grid').DataTable( {
"order": [[ 1, "desc" ]],
"processing": true,
"serverSide": true,
"ajax":{
url :"employee-grid-data.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
} );
查看数据表文档以获取更多信息:https://datatables.net/examples/basic_init/table_sorting.html