10

In R DT you can define the table control elements with code such as:

# only display the table, and nothing else
library(DT)
datatable(mtcars, options = list(dom = 't'))

The t above is a DOM. The DOM element l controls the length changing input control, basically how long your table will be. It looks like this.

show entries selection

This length changing input control defaults to a value of 10. How can I change this default value to 25, 100, perhaps even "All"?

Display name
  • 4,153
  • 5
  • 27
  • 75

3 Answers3

9

We can set iDisplayLength:

datatable(mtcars, options = list(iDisplayLength = 25))

enter image description here

Related post:

zx8754
  • 52,746
  • 12
  • 114
  • 209
6

You can change it to 3 by datatable(mtcars, options = list(dom = 't', pageLength = 3)).

This will get you your desired results:

datatable(mtcars, options = list(dom = 't',
  lengthMenu = list(c(25, 100, -1), c('25', '100', 'All')),
  pageLength = 25
))
tester
  • 1,662
  • 1
  • 10
  • 16
-1

Oh my, poke and hope until you find the secret combo, setting pageLength does nothing until you set scrollY to TRUE.

options = list(pageLength = 10, scrollY = TRUE) 
Dylan_Gomes
  • 2,066
  • 14
  • 29