4.2 Recommended options with DT
Code
datatable(d,
width=480,
class='display compact nowrap',
rownames=F,
filter = 'top',
style='auto',
extensions = c('ColReorder', 'FixedHeader', 'KeyTable', 'Buttons'),
options = list(
orderClasses=T, ## highlight the ordered column
#autowidth=T, ##
dom = 'Brtip', ## https://datatables.net/reference/option/dom
buttons = c('copy', 'csv', 'excel'), ## download buttons
pageLength=30, ## rows per page
columnDefs=list(list(orderSequence = c('desc', 'asc'),
targets = '_all' )) ## sort desc first
# initComplete = JS( ## change colors of rows.
# "function(settings, json) {",
# paste0("$('tr.odd').css({'background-color': '", publightgray, "'});"),
# paste0("$('tr.even').css({'background-color': '", pubbackgray, "'});"),
# "}"))
)
)
More examples and options can be found here https://rstudio.github.io/DT or here https://datatables.net/examples/index. Also note that in https://rstudio.github.io/DT/options.html it says
When there are some options that you want to set for multiple tables produced from the same R session, you can use the global option named DT.options. For example:”
options(DT.options = list(pageLength = 5, language = list(search = 'Filter:')))