DT数据表中的列对齐 [英] Column alignment in DT datatable
问题描述
在我的闪亮
应用中,我使用的是 DT $ c中的
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屋!