Luis
Luis

Reputation: 61

Change column filter "All" label in datatable

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")))

enter image description here

I tried different options such as replacing oTable with aoColumns, sSearchCols, aoSearchCols and aoColumnDefs but nothing seems to work.

Upvotes: 2

Views: 343

Answers (1)

zx8754
zx8754

Reputation: 56219

Using callback (related GitHub issue 281):

library(DT)

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

enter image description here

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

Related Questions