Search code examples
rdatatablesdt

How to freeze/fix the last row on a DT::datatable output in R?


I have a datatable in my shinyapp with a lot of rows so i need to use the scrollY = TRUE option. Im wondering if there is a way to fix the last row so i dont need to scroll to see this specific row. I know this is easy to do with columns, but rows... not sure.


Solution

  • It's possible to fix (the header and) the footer with the FixedHeader extension:

    library(DT)
    
    dat <- iris
    
    sketch <- htmltools::tags$table(
      tableHeader(c("",names(dat))),
      tableFooter(c(
        "", "this", "is", "my", "awesome", "row"
      ))
    )
    
    datatable(
      dat, container = sketch,
      extensions = "FixedHeader",
      options = list(
        paging = FALSE,
        scrollY = 300,
        scrollCollapse = TRUE,
        fixedHeader = list(header = TRUE, footer = TRUE)
      )
    )