[英]JQuery datatables ordering by Desc oder
I'm using JQuery datatable for my table however I want the last entry to appear first as in the table to appear in a descending order. 我正在为表使用JQuery数据表,但是我希望最后一个条目像表中的第一个出现一样以降序显示。 Tried changing the PHP MYSQL select statement but not working. 尝试更改PHP MYSQL select语句,但不起作用。 I thought, could this be the code to arrange as to my needs? 我想,这可以是根据我的需求安排的代码吗? I f so, any one lead me how to oder the same? 如果是这样,任何人都会带领我如何做到相同? Thank you... 谢谢...
<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>
NB: Assuming your first column of table is some kind of auto incremented id 注意:假设表格的第一列是某种自动递增的ID
I think you should try this :- 我认为您应该尝试这样做:
$(document).ready(function(){
$('#employee-grid').DataTable({
"order": [[ 1, "desc" ]]
});
});
For more info please go to this link :- https://datatables.net/examples/basic_init/table_sorting.html 有关更多信息,请转到此链接: -https : //datatables.net/examples/basic_init/table_sorting.html
You need to specify the default order column, like this: 您需要指定默认的订单列,如下所示:
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");
}
}
} );
Check the Datatables docs for more information: https://datatables.net/examples/basic_init/table_sorting.html 检查数据表文档以获取更多信息: https : //datatables.net/examples/basic_init/table_sorting.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.