As per below the documentation (https://rstudio.github.io/DT/extensions.html), the below code should collapse first and second columns by default(0,1), but when tried it is displaying all columns by default.
this is a misunderstanding, the example and description show that this code adds a column visibility button that allows some chosen columns to be hidden by pressing their buttons in the column vis butto; in this example the 1st column can not be hidden as it has been left off the list.
Here is an amendment to the code which shows adjusting the initial hidden columns.
library(DT)
datatable(
iris, rownames = FALSE,
extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = list(list(extend = 'colvis', columns = c(0,1,2,3,4))) # all 5 are hideable/showable by the button
,columnDefs = list(list(visible=FALSE, targets=c(0,1)) # first two start hidden
)
))
Awesome thank a lot. Last clarification, Can we add another feature named "ALL" in the drop down so that when the user selects all, all columns should be visible.
In other words, just to avoid user selecting each column one by one. Can this be achieved ?