2015-04-05 78 views
0

除了数据表中的正常排序功能,我想默认情况下以降序显示我的数据表(按照从mysql结果中的id排序)。但是,如果没有任何错误,它会以升序显示数据表。默认情况下,为什么数据表不能以降序显示数据?

这里是我迄今所做的: JS:

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

和我的服务器端: PHP:

SELECT s . * , c.name AS cls, sec.name AS sect 
        FROM `student` s 
        INNER JOIN cls c 
        ON s.cls = c.id 
        INNER JOIN sect sec 
        ON s.sect = sec.id 
        ORDER BY s.id DESC 

HTML:

<table class="table table-striped 
table-bordered bootstrap-datatable datatable" id="example"> 
//table data here 
</table> 

任何建议和帮助非常感谢。

+0

难道是JS是颠倒SQL的顺序吗? – 2015-04-05 20:59:03

+0

也许你正在订购两次: 在你的SQL:DESC,然后在JS:再次DESC。 DESC * DESC = ASC – 2015-04-06 02:08:56

回答

0

我正面临同样的问题。我们可以通过在数据表中按降序逐个添加数据来解决它。通过html创建一个空表并且

var table = $("#example").dataTable(); 

使用ajax并以变量降序获取数据。

$.ajax({ 
      // params 
      success(data){ 
      table.fnClearTable(); // to clear the table 
      $.each(data, function(i,item)){ 
       table.fnAddData([data.item1, data.item2,data.item3,.....]) // adding data 
      } 
      table.fnDraw(); // re draw the table 
     } 
    }) 
+0

如果您发现解决方案请更新 – Azeem112 2017-09-28 07:26:03

相关问题