我使用RenderDataTable来显示数据帧。使用order = list(list(column_number, 'desc'))对除索引之外的任何列都有效。我想按降序排序,以便在顶部看到最新的条目。使用0在RenderDataTable中不起作用。有没有办法强制在选项列表中进行降序排序?默认值总是按索引进行升序。
以下是我的尝试:
DT::datatable(reporting[],
options = list(
lengthMenu = c(10, 25, 50, 100, 150, 200),
order = list(list(0, 'desc')),
pageLength = 25
))发布于 2016-07-01 17:31:16
您可以尝试order = DT[order(as.numeric(rownames(DT)),decreasing = TRUE)],它应该按降序顺序排列数据。尽管如此,没有数据就很难复制您的问题。下面是我能够提供的一个工作示例:
DT = data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6), v=1:9)
DT
x y v
1: b 1 1
2: b 3 2
3: b 6 3
4: a 1 4
5: a 3 5
6: a 6 6
7: c 1 7
8: c 3 8
9: c 6 9DT[order(as.numeric(rownames(DT)),decreasing = TRUE)]
x y v
1: c 6 9
2: c 3 8
3: c 1 7
4: a 6 6
5: a 3 5
6: a 1 4
7: b 6 3
8: b 3 2
9: b 1 1https://stackoverflow.com/questions/38144072
复制相似问题