我正在尝试将数据表中显示的默认标签(“全部”)更改为其他内容,例如:“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,但似乎没有任何效果。
最佳答案
使用回调(related GitHub issue 281):
library(DT)
datatable(head(diamonds),
filter = 'top',
callback = JS("$(\"input[type='search']\").attr('placeholder','xyz');")
)
或者一点技巧,将datatable对象分配给一个变量,然后gsub:
myDT <- datatable(head(diamonds),
filter = 'top')
myDT[["x"]][["filterHTML"]] <- gsub('placeholder=\"All\"', 'placeholder=\"xyz\"',
myDT[["x"]][["filterHTML"]])
myDT
关于javascript - 更改数据表中的列过滤器 "All"标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64443411/