Place pagination at top of DT Datatable in R?
Asked Answered
S

2

5

I'm working with a very long datatable and would like to place the pagination (1, 2, 3, ...15, next) at the top rather than the bottom of the table.

I know the DOM elements can be included/excluded as an option, but I don't see how to actually move them around.

How can a simple table like this move the pagination to the top?

library(DT)
datatable(iris)
Subduct answered 11/1, 2020 at 2:41 Comment(0)
D
6

You can use dom options. See https://datatables.net/reference/option/dom for details on the various options available. To place pagination at top use:

datatable(iris, options = list(dom = '<"top" p>'))

enter image description here

If you also need other elements such as information and search, add them in the same way, e.g.

datatable(iris, options = list(dom = '<"top" pif>'))

enter image description here

Dewittdewlap answered 11/1, 2020 at 2:55 Comment(1)
For pagination both at top and bottom: datatable(iris, options = list(dom = '<"top"lpf<"clear">>rt<"bottom"ip<"clear">>' ))Licko
D
2

The "dom" argument passed as a list in the options argument to datatable seems to arrange things.

datatable(head(iris, 30), options = list(dom = '<lfp<t>i>'))

enter image description here The t is for the table, p for pagination, between < and < at the top, between > and > at the bottom.

datatable(head(iris, 30))

enter image description here

Doolie answered 11/1, 2020 at 3:43 Comment(2)
this seems only incrementally different to my earlier answerDewittdewlap
You must've posted while I was looking for the answer. Looks like we got to the same place, but you beat me by a few minutes, and with better formatting.Doolie

© 2022 - 2024 — McMap. All rights reserved.