Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove padding in datatable column

Tags:

r

dt

shiny

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.

like image 978
Zeus Avatar asked Mar 06 '23 18:03

Zeus


1 Answers

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
        )
      )
  })
like image 88
Zeus Avatar answered Mar 20 '23 00:03

Zeus