简体   繁体   English

如何在数据表中一次对两列进行排序

[英]How to sort two columns at once in datatables

I have a table like below , I want to sort column A ascending and column B descending. 我有一个像下面的表格,我想对A列升序和B列降序进行排序。

ABC 1 4 string1 2 11 string2 1 13 string3 2 43 string4

And, I want to sort by both A (ascending) and B (descending) at once, to get this: 而且,我想同时按A(升序)和B(降序)进行排序,以获得以下信息:

ABC 1 13 string3 1 4 string1 2 43 string4 2 11 string2

Right now I can able to sort one column with following code 现在,我可以使用以下代码对一列进行排序

oTable.api().columns( ['.acol'] ).order("asc").draw();

From the docs : 文档

You can specify multiple columns in order command. 您可以在order命令中指定多个列。 In your case: 在您的情况下:

oTable.api().columns( ['.acol', '.bcol'] )
            .order([ [ '.acol', 'asc' ], [ '.bcol', 'desc' ] ])
            .draw();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM