Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the horizontal scrollbar visible in DT::datatable

Using R shiny & DT package, I am creating certain tables. The number of columns vary as per user input & is not fixed. I have included the following code snippet to include a horizontal scrollbar so that when the number of columns is large, the user can scroll through the columns that are not directly visible.

server.R:

output$results <- DT::renderDataTable({     DT::datatable(data = datasetInput(),                   options = list(scrollX = TRUE,...)                   )   }) <code reduced for brevity> 

Using the above code, the Horizontal scrollbar is not visible at first but appears when I click on a row and hit right arrow on my keyboard. Is there any way the scroll bar becomes visible as soon as the table is fired up, no matter how many columns I have, and I can drag the scrollbar using the mouse pointer?

Update:

I tried the code in the answer below and this is what I see - no horizontal scrollbar.

enter image description here

like image 727
Komal Rathi Avatar asked Jun 10 '15 19:06

Komal Rathi


People also ask

How do I make my horizontal scrollbar visible?

To show the scrollbars always on the webpage, use overflow: scroll Property. It will add both horizontal and vertical scrollbars to the webpage. To add only horizontal scrollbar use overflow-x: scroll property and for vertical scrollbar use overflow-y: scroll property.

How do I make a horizontal scroll in Datatable?

DataTables has the ability to show tables with horizontal scrolling, which is very useful for when you have a wide table, but want to constrain it to a limited horizontal display area. To enable x-scrolling simply set the scrollX parameter to be true .

How do you change the vertical and horizontal scrollbar in a table?

Suppose we want to add a scroll bar option in HTML, use an “overflow” option and set it as auto-enabled for adding both horizontal and vertical scroll bars. If we want to add a vertical bar option in Html, add the line “overflow-y” in the files.

How do I add a horizontal scrollbar?

To make a scroll box with a horizontal scroll, you need to use the overflow-x property. Specifically, you need to use this code: overflow-x:scroll; . This tells your browser to create scroll bars on the x (horizontal) axis, whenever the contents of the container is too wide.

How do I make a table scroll horizontally in DataTables?

Scroll - horizontal. DataTables has the ability to show tables with horizontal scrolling, which is very useful for when you have a wide table, but want to constrain it to a limited horizontal display area. To enable x-scrolling simply set the scrollX parameter to be true.

What's the point of the horizontal scroll bar?

Apparently the horizontal bar is added to account for the space taken up by the vertical bar, so the horizontal scroll available is only a few pixels. This is completely unnecessary and doesn't look good. Is there a way to get rid of the horizontal scroll?

How do I enable X-scrolling in DataTables?

Scroll - horizontal DataTables has the ability to show tables with horizontal scrolling, which is very useful for when you have a wide table, but want to constrain it to a limited horizontal display area. To enable x-scrolling simply set the scrollX parameter to be true.

What is the use of scrolly option in SQL Server?

The scrollY option is used to specify whether vertical scrolling should be enabled in a DataTable. This option will restrict the height of the DataTable to the given value and allow the user to scroll any overflowing content in the table itself.


1 Answers

I don't think you can (or should) force a scrollbar easily if you don't need one, but the above code works fine for me, it shows a scrollbar when the page initializes. Maybe the problem is with the data or something else.

Here's a minimal example that has a horizontal scrollbar on page load

runApp(shinyApp(   ui = fluidPage(     DT::dataTableOutput("results", width = 300)   ),   server = function(input, output, session) {     output$results <- DT::renderDataTable(       mtcars,       options = list(scrollX = TRUE)     )   } )) 
like image 169
DeanAttali Avatar answered Oct 08 '22 20:10

DeanAttali