We can customize DataTables through the options
argument of
DT::datatable()
. Below is a brief explanation of the examples
above:
-
the option
pageLength = 25
changes the default number of rows to display from 10 to 25; -
the option
lengthMenu = list(c(5, 15, -1), c('5', '15', 'All'))
sets the length menu items (in the top left corner); it can be either a numeric vector (e.g.c(5, 10, 30, 100)
), or a list of length 2 -- in the latter case, the first element is the length options, and the second element contains their labels to be shown in the menu; -
paging = FALSE
disables pagination, i.e. all records in the data are shown at once; alternatively, you can setpageLength = -1
; -
searching = FALSE
disables searching, and no searching boxes will be shown; -
any character strings wrapped in
JS()
will be treated as literal JavaScript code, and evaluated usingeval()
in JavaScript, so we can pass, for example, JS functions to DataTables;