如何在DT :: datatable中设置多个选项列表和扩展名 [英] How to set multiple option list and extensions in DT::datatable

查看:268
本文介绍了如何在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 属性。有关详细信息,请查看此链接中的每个字母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屋!

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