firmo23
firmo23

Reputation: 8454

Change the background color of search box and entry box in a datatable

I would like to change the background color of the 'number of entries' and 'search box' at the top of the data table from white to -lets say- gray. Is this possible?

library(DT)
datatable(iris)

Upvotes: 0

Views: 983

Answers (2)

Stéphane Laurent
Stéphane Laurent

Reputation: 84639

library(DT)

callback <- c(
  "$('#DataTables_Table_0_length select').css('background-color', 'orange');",
  "$('#DataTables_Table_0_filter input').css('background-color', 'yellow');"
)

datatable(iris, callback = JS(callback))

enter image description here

Upvotes: 2

Yifu Yan
Yifu Yan

Reputation: 6116

Use callback argument:

Write JavaScript to select the HTML elements and change their CSS.

For example, I modified the background color using codes below. You can use similar approach to change the CSS of the search box.

DT::datatable(iris,elementId = "thistable",
              callback = DT::JS("$('#thistable div[role=\"status\"]').css('background-color','red')"))

enter image description here

Upvotes: 0

Related Questions