如何在DT :: datatable中设置多个选项列表和扩展名 [英] How to set multiple option list and extensions in DT::datatable
问题描述
我试图应用 datatable选项和扩展名来绘制一个表。它的工作,如果遵循的参考,但ColVis不工作,当我组合/应用多个扩展。任何想法?
I tried to apply datatable options and extensions to plot a table. Its work if follow the reference but ColVis doesn't work when I combined / applied multiple extensions. Any idea?
df %>%
datatable(., caption="Table 3.4.1 : Partial Matching Teams' Name.",
extensions=list('ColReorder','ColVis', list(FixedColumns=list(leftColumns=2))),
options=list(autoWidth=TRUE,
dom='C<"clear">lfrtip',
colVis=list(exclude=c(0, 1),
activate='mouseover'),
colReorder=list(realtime=TRUE),
scrollX=TRUE,
scrollCollapse=TRUE))
推荐答案
根据 DT手册选项关联一些扩展需要放在命名列表中。如果指定选项
属性中的选项,则必须分配 NULL
。
According to the DT manual options associated with some extensions needs to be placed in a named list. If one specifies options in options
attribute, then NULL
must be assigned.
datatable(.,extensions=list("ColReorder" = NULL,
"ColVis" = NULL,
"FixedColumns"=list(leftColumns=2))
由于 dom $ c不足而产生另一个错误$ c>属性。有关详细信息,请查看此链接。
中的每个字母dom
与表输出的指定元素链接。与 extension
相关联的大写字母和带有表格元素的小写( R
- Col R eorder,
C
- C olVis, T
- 表 T ools, t
- t 能,
- 表我 nfo等)。如果示例'R'缺失,因此Col R eorder不能w ork。将所有的代码放在正确的代码中加入TableTools:
Another error is generated due to insufficient dom
attribute. For more info see this link . Each letter in dom
is linked with specified element of table output. Uppercase letters associated with extension
and lowercase with table elements (R
- ColReorder, C
- ColVis, T
- TableTools, t
- table, i
- table info etc.). In case example 'R' is missing, and therefore ColReorder couldn't work. Putting all together below correct code with TableTools added:
iris %>%
datatable(
extensions = list("ColReorder" = NULL,
"ColVis" = NULL,
"TableTools" = NULL,
"FixedColumns" = list(leftColumns=2)),
options = list(autoWidth=TRUE,
oColReorder = list(realtime=TRUE),
oColVis = list(exclude=c(0, 1), activate='mouseover'),
oTableTools = list(
sSwfPath = "//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/swf/copy_csv_xls.swf",
aButtons = list("copy","print",
list(sExtends = "collection",
sButtonText = "Save",
aButtons = c("csv","xls")))),
dom = 'CRTrilftp',
scrollX = TRUE,
scrollCollapse = TRUE))
升级! >
由于DT已升级(v0.1.56)扩展名 TableTools
和 ColVis
不再可用。根据新的教程,可以通过按钮 code>扩展名。新版本的包更加一致,添加扩展比以前更容易:
Upgrade!
As DT has upgraded (v0.1.56) extensions TableTools
and ColVis
is no longer available. According to the new tutorial above extension are possible through buttons
extension. New version of package is more consistent and adding extensions is easier than before:
DT:::datatable(
iris,
escape=F,
filter = "top",
rownames= F,
extensions = list("ColReorder" = NULL,
"Buttons" = NULL,
"FixedColumns" = list(leftColumns=1)),
options = list(
dom = 'BRrltpi',
autoWidth=TRUE,
lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
ColReorder = TRUE,
buttons =
list(
'copy',
'print',
list(
extend = 'collection',
buttons = c('csv', 'excel', 'pdf'),
text = 'Download'
),
I('colvis')
)
)
)
这篇关于如何在DT :: datatable中设置多个选项列表和扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!