gpt4 book ai didi

javascript - JQuery 数据表按描述顺序排序

转载 作者:行者123 更新时间:2023-12-03 06:36:53 25 4
gpt4 key购买 nike

我在表中使用 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>

最佳答案

<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>

注意:假设表的第一列是某种自动递增的 id

关于javascript - JQuery 数据表按描述顺序排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38158513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com