Reputation: 61
I am trying to change the default label appearing in a DataTable (which is "All") to something else, for example to: "Sélectionner"
.
Here is my code :
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")))
I tried different options such as replacing oTable with aoColumns, sSearchCols, aoSearchCols and aoColumnDefs but nothing seems to work.
Upvotes: 2
Views: 343
Reputation: 56219
Using callback (related GitHub issue 281):
library(DT)
datatable(head(diamonds),
filter = 'top',
callback = JS("$(\"input[type='search']\").attr('placeholder','xyz');")
)
Or a bit of a hack, assign datatable object to a variable, then gsub:
myDT <- datatable(head(diamonds),
filter = 'top')
myDT[["x"]][["filterHTML"]] <- gsub('placeholder=\"All\"', 'placeholder=\"xyz\"',
myDT[["x"]][["filterHTML"]])
myDT
Upvotes: 3