0

I have created a datatable in R as you can see in the image. I have 2 things I would like to change:

  1. I would like column 1 to be wider so that the pay bands are shows all in one line e.g £15,001- £20,000 - how would I do that?

  2. Can I remove the search bar? enter image description here

This is my current code:

tab1a <- datatable(tab1a,
                   fillContainer = FALSE,
                          rownames = FALSE,
                          extensions = 'Buttons', options = list(
                            columnDefs = list(list(className = "dt-body-right", targets = "_all"),
                                              list(className = "dt-center", targets = "_all")),
                            pageLength = 20,
                            lengthMenu = c(5, 10, 15, 20),
                            dom = 'Bfrtip',
                            buttons = list(
                              list(extend = "pdf", exportOptions = list(columns = ":visible")),
                              list(extend = "excel", exportOptions = list(columns = ":visible")),
                              list(extend = "csv", exportOptions = list(columns = ":visible")),
                              list(extend = "copy", exportOptions = list(columns = ":visible")),
                              list(extend = "print", exportOptions = list(columns = ":visible"))
                            )
                              ))
zx8754
  • 52,746
  • 12
  • 114
  • 209
atm1984
  • 19
  • 3
  • 1
    possible duplicate? first question: https://stackoverflow.com/questions/25205410/r-shiny-set-datatable-column-width, second: (possibly) https://stackoverflow.com/questions/35624413/remove-search-option-but-leave-search-columns-option – Wimpel Jan 26 '23 at 16:25
  • Hi, I was able to find Searching = FALSE to get rid of the search bar but still struggling to change column widths. – atm1984 Jan 26 '23 at 16:46

1 Answers1

0

The index of the column starts from '0'. Also set option scrollX=TRUE and searching = F. The width of the first column is set to be 200 as an example.

datatable(tab1a, 
          fillContainer = FALSE,
                    rownames = FALSE,
                    extensions = 'Buttons',
          options=list(columnDefs = list( list(className = "dt-body-right", targets = "_all"),
                                          list(className = "dt-center", targets = "_all"),
                                          list(width = 200, targets = c(0))
                                         ),
                       autoWidth = TRUE,
                       scrollX=TRUE,
                       searching = F,
                                   pageLength = 20,
                                   lengthMenu = c(5, 10, 15, 20),
                                   dom = 'Bfrtip',
                                   buttons = list(
                                     list(extend = "pdf", exportOptions = list(columns = ":visible")),
                                     list(extend = "excel", exportOptions = list(columns = ":visible")),
                                     list(extend = "csv", exportOptions = list(columns = ":visible")),
                                     list(extend = "copy", exportOptions = list(columns = ":visible")),
                                     list(extend = "print", exportOptions = list(columns = ":visible"))
                                   )
                       )
          ) 
aloe
  • 26
  • 1