Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to freeze columns in reactable #19

Open
sabhcy opened this issue Dec 8, 2019 · 3 comments
Open

How to freeze columns in reactable #19

sabhcy opened this issue Dec 8, 2019 · 3 comments

Comments

@sabhcy
Copy link

@sabhcy sabhcy commented Dec 8, 2019

if we need to freeze 5 left most column and provide a horizontal scroll bar afterwards, how do we do that with reactable?

@glin
Copy link
Owner

@glin glin commented Jan 11, 2020

You can freeze columns using the position: sticky CSS property, but it's not the easiest to use right now. Making a single left or right column sticky is pretty straightforward, but making multiple columns sticky requires you to know the widths of columns.

I think it'd be nice to build this into reactable in the future, but for now, you'll have to add some likely-messy CSS yourself. I've created some examples of single/multiple sticky columns here:
https://glin.github.io/reactable/articles/sticky-columns.html

Also note IE11 doesn't support position: sticky, if that's important. I think it's possible to freeze columns without position: sticky, but it'd be much harder.

screenshot of table

@analytichealth
Copy link

@analytichealth analytichealth commented Apr 1, 2020

Is there a way to freeze the checkbox column too? As a simple example, when using a selectionId you will see the checkbox column does not stick:

library(reactable)

reactable(MASS::Cars93, 
	selection = "multiple", selectionId = "table_rows_selected", onClick = "select",
	columns = list(
  Manufacturer = colDef(minWidth = 150, 
    style = list(position = "sticky", left = 0, background = "#fff", zIndex = 1),
    headerStyle = list(position = "sticky", left = 0, background = "#fff", zIndex = 1)
  )
))
@glin
Copy link
Owner

@glin glin commented Apr 11, 2020

@analytichealth I just added the ability to customize the row selection column to make that easier: https://glin.github.io/reactable/articles/examples.html#customize-the-selection-column

You can now add inline styles or classes to the selection column like this:

reactable(
  MASS::Cars93,
  selection = "multiple",
  columns = list(
    .selection = colDef(
      style = list(position = "sticky", left = 0, background = "#fff", zIndex = 1),
      headerStyle = list(position = "sticky", left = 0, background = "#fff", zIndex = 1)
    )
  )
)

Here are some examples of freezing the selection column: https://glin.github.io/reactable/articles/sticky-columns-selection.html. The only other tricky part is that selection columns have a different, undocumented default width (36px), so I'd recommend setting the width explicitly, in case the default ever changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.