4

Is there any way of setting the datatable options to reduce the column padding? This link suggested using autoWidth=TRUE along with scrollX=TRUE, but it doesn't work in my code.

As you can see in the image below there is a big gap between columns forcing the user to scroll across, which I'd prefer to avoid if possible. This link and this one have the same problem in java

enter image description here

Here's the code for rendering the datatable.

output$book_table <-  DT::renderDT(RVTables$book %>% 
                                     filter(deal==as.numeric(input$deal_choice)),
                                   selection = list(mode="single",selected=row_edited),
                                   editable = TRUE,
                                   rownames = FALSE,
                                   options=list(
                                     autoWidth=TRUE,
                                     scrollX = TRUE,
                                     ordering=FALSE,
                                     pageLength=12,
                                     scrollY = TRUE,
                                     bLengthChange= FALSE,
                                     searching=FALSE
                                   )
)

Thanks for any help.

Zeus
  • 1,496
  • 2
  • 24
  • 53
  • 'strategy' col width is the same as column name length so if you want it to be smaller, make column name with wrapped text or smaller. – Aleksandr Jul 23 '18 at 06:00
  • yes I could do that, but is there no easy way to reduce the gap between column headings? there's a lot of padding after the name – Zeus Jul 23 '18 at 06:19
  • As far as I know, no. Length of the column is no less than length of column name. – Aleksandr Jul 23 '18 at 06:34
  • that's ok, but there seems to be padding btw column headings, look at the gap btw the number columns, and columns 2 and 3 – Zeus Jul 23 '18 at 06:37

1 Answers1

7

After some google searching I found the line of code class="compact cell-border", which reduces the padding around column headers. Here is my code to render the table in case it helps anyone else.

output$book_table <- DT::renderDataTable({    
    DT::datatable(
      deal_reactive(),
      editable = TRUE,
      rownames = FALSE,
      class="compact cell-border",
      selection = list(mode = "single", 
                       target = "row", 
                       selected = previous_row),
      options = list(
        dom="t",
        autoWidth=TRUE,
        scrollX = TRUE,
        ordering=FALSE,
        pageLength = 28, 
        bLengthChange= FALSE,
        displayStart = previous_page,
        searching=FALSE
        )
      )
  })
Zeus
  • 1,496
  • 2
  • 24
  • 53