0

I have a very basic need but I can't find any similar recent question. I have a big data table in my R Shiny app. When scrolling horizontally and / or vertically, I would need to do what we can easily do in excel, that is, freeze the first N columns and freeze the first N rows. My code below shows how to freeze the first 3 columns but I can't find a way to simultaneously freeze also the first 4 rows.

df <- datatable(df_data, 
                          rownames= F,
                          filter = 'top',
                          #lengthChange = T,
                          extensions = c("Buttons","FixedColumns"),
                          caption = paste0("County Data."),
                          options = list(scrollX = TRUE
                                         , autoWidth = TRUE
                                         , pageLength = -1
                                         , lengthMenu = list(c(5, 10, 15, 20, 25, -1), c('5', '10', '15', '20', '25', 'All'))
                                         #,  columnDefs = list(list(width = '200px', targets = c(0)  ))
                                         , initComplete = JS("function(settings, json) {","$(this.api().table().header()).css({'font-size': '12px'});","}")
                                         ,  columnDefs = list(list(width = '200px', targets = c(0)  ),
                                                              list(width = '50px', targets = c(1,2,3)  ),
                                                              list(width = '100px', targets = c(seq(from = 3, to = dim(df_data)[2]-1))  )  )
                                         , dom = 'Blfrtip'
                                         , searching = T 
                                         , info = T
                                         , fixedColumns = list(leftColumns = 3)
                                         , buttons = c('copy', 'csv', 'excel', 'pdf')
                          )) 
Angelo
  • 1,594
  • 5
  • 17
  • 50
  • 1
    related post, could be useful: https://stackoverflow.com/questions/26228786/freezing-header-and-first-column-using-data-table-in-shiny – Dominic Comtois Mar 29 '21 at 19:55
  • Hi @DominicComtois, I actually saw that post but I have no idea of how to adampt the JS to my example above. I wonder if there's any more recent solution. – Angelo Mar 29 '21 at 19:57
  • 1
    I'd like to help but I'm not an expert DT user, I just happened to see the related post. It sure doesn't look simple. – Dominic Comtois Mar 29 '21 at 20:08

0 Answers0