【问题标题】:Change column filter "All" label in datatable更改数据表中的列过滤器“全部”标签
【发布时间】:2021-02-03 04:16:44
【问题描述】:

我正在尝试将出现在 DataTable 中的默认标签(即“All”)更改为其他内容,例如:"Sélectionner"

这是我的代码:

library(DT)   

datatable(head(diamonds),
          rownames = F,
          class = 'cell-border stripe',
          extensions = c('Buttons', 'Select', 'SearchPanes', 'FixedColumns'),
          selection = 'none',
          filter = 'top',
          options = list(autoWidth = T,
                         dom = 'Bfrt',
                         pageLength = length(head(diamonds)),
                         columnDefs = list(list(width = '150px', targets = list(1,2,3)),
                                           list(width = '300px', targets = list(5))),
                         searchHighlight = TRUE,
                         buttons = c('csv', 'excel', 'pdf'),
                         scrollY=600,
                         scrollX=300,
                         scroller = TRUE,
                         deferRender = TRUE,
                         scrollCollapse = F,
                         oLanguage = list("sSearch" = "Rechercher :",
                                          "sZeroRecords" = "Aucun résultat disponible"),
                         oTable = list("aoSearchCols" = "Aloooo")))

我尝试了不同的选项,例如用 aoColumns、sSearchCols、aoSearchCols 和 aoColumnDefs 替换 oTable,但似乎没有任何效果。

【问题讨论】:

  • 不确定是否有修复,但看起来是 hardcoded 变成了 DT:::filterRow()

标签: javascript r dt


【解决方案1】:

使用回调 (related GitHub issue 281):

library(DT)

datatable(head(diamonds),
          filter = 'top',
          callback = JS("$(\"input[type='search']\").attr('placeholder','xyz');")
          )

或者有点hack,将datatable对象赋值给一个变量,然后gsub

myDT <- datatable(head(diamonds),
                  filter = 'top')

myDT[["x"]][["filterHTML"]] <- gsub('placeholder=\"All\"', 'placeholder=\"xyz\"', 
                                    myDT[["x"]][["filterHTML"]])

myDT

【讨论】:

    猜你喜欢
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多