DT数据表中的列对齐 [英] Column alignment in DT datatable

查看:93
本文介绍了DT数据表中的列对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的闪亮应用中,我使用的是 DT datatable 函数$ c>库来构造一个表,并希望在中心对齐列。我可以使用 formatStyle('column',textAlign ='center'),但它只影响列主体,而不影响标题。

解决方案

我们必须在参数 option 的自变量中设置 columnDefs 函数 datatable


请参见以下示例:

  library(DT)

datatable(head(iris),
rownames = FALSE,
options = list(
columnDefs = list(list(className =' dt-center',目标= 0:4))


设定目标。在该示例中,所有5列都对齐到中心。 ( targets = 0:4 )。


最后,请注意,列号从0开始,而不是从1开始。


注意::我们可以使用 targets = _ all 应用于所有列,而不考虑列数。 / p>

In my shiny app I am using datatable function from DT library to construct a table and want to align columns on center. I can use formatStyle('column', textAlign = 'center') but it affects only column body and not the header.

解决方案

We have to set columnDefs in the argument option of the function datatable.

See example below:

library(DT)

datatable(head(iris),
          rownames = FALSE,
          options = list(
            columnDefs = list(list(className = 'dt-center', targets = 0:4))
            )
          )

We have to set the target. In the example all the 5 columns are aligned to "center" (targets = 0:4).

Finally, note that column numbers start from 0, not from 1.

Note: we can use targets="_all" to apply to all columns regardless of number of columns.

这篇关于DT数据表中的列对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆