【问题标题】:Datatables Buttons to show/hide RowGroups用于显示/隐藏行组的数据表按钮
【发布时间】:2021-10-11 08:42:26
【问题描述】:

我有一个使用 RowGroups 和 Buttons/Colvis 的表。

很像 Colvis 的按钮,我希望有按钮来仅显示特定的 RowGroups。目前我有一张长桌,里面有很多 RowGroups。用户通常只想看到特定的列组,我想防止他们不得不一直向下滚动。

从下面的示例中,想象有一个按钮“行组”可见性,与 Colvis 中的列可见性完全相同。

【问题讨论】:

  • 您希望它们可折叠吗?还是完全隐藏?
  • 两者都可以,但最好完全隐藏。可折叠会导致某人不得不经常隐藏大量组,而通过一个按钮将它们全部隐藏起来要容易得多。

标签: r shiny datatables


【解决方案1】:

我所描述的可以使用 SearchPanes 扩展来完成。您可以在与 rowGroup 目标相同的列上选择 searchPanes 目标。

您还可以将 searchPanes 设置为按钮。

我的代码示例,在 renderDT 中使用:

output$tbl <- renderDT({
        datatable(data,
                  rownames = FALSE,
                  caption = 'Some caption',
                  extensions = c('ColReorder', 'RowGroup', "Buttons",
                                 "Select", "SearchPanes"),
                  options = list(#DOM options
                                 dom = "Bfrtip",
                                 #Rowgroup options
                                 rowGroup = list(dataSrc = c(0,2)),
                                 #Buttons options
                                 stateSave = TRUE,
                                 buttons = c('colvis', 'csv', 'excel', 'searchPanes'),
                                 #ColReorder options
                                 colReorder = TRUE,
                                 #SearchPanes options
                                 columnDefs = list(
                                   list(searchPanes = list(show = FALSE), targets = 1:7)),
                                 selection = 'none',
                                 #Overige options
                                 paging = FALSE)
      )}, server = FALSE)

也感谢 Matt Herman 的博文:https://mattherman.info/blog/dt_searchpanes/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    相关资源
    最近更新 更多