design-system-react icon indicating copy to clipboard operation
design-system-react copied to clipboard

Add Support for Data Table Scrolling

Open kwilloughby opened this issue 10 years ago • 19 comments

I'd like to add support for data table scrolling. Below is an example. In this example the table header remains visible at all times. The example also shows horizontal scrolling because the table is too wide.

image

kwilloughby avatar Sep 14 '16 22:09 kwilloughby

@pixelprodotco for visibility.

kwilloughby avatar Sep 14 '16 22:09 kwilloughby

I know how to do this is style CSS hacks. Is there's an SLDS way / pattern to do it?

Review #255 for more background on this issue.

interactivellama avatar Sep 15 '16 14:09 interactivellama

@chriscorwin We also need this feature for IoT cloud application. Have you started looking into this? Thanks.

leiwlotus avatar Oct 11 '16 20:10 leiwlotus

For what it's worth, I was able to get this to work using flexbox if that's a valid approach. http://jsfiddle.net/CrSpu/10356/ Note: The column headers are slightly misaligned due to the width the scrollbar takes up on the table body. This can be pretty easily solved though. Thoughts?

michaelcclayton avatar Oct 11 '16 21:10 michaelcclayton

I wasn't able to figure out the scroll bar width easily when I tried earlier. @ivanbogdanov This is the scrolling problem we are talking about. i.e how to scroll table body only while keeping the header fields aligned to table cells.

leiwlotus avatar Oct 11 '16 21:10 leiwlotus

@michaelcclayton A potential issue is very wide tables.

The flexblox thing will simply squeeze them all in.

Additionally, the headers won't scroll horizontally with the columns.

large-flexbox-datatable

chriscorwin avatar Nov 03 '16 16:11 chriscorwin

@kwilloughby The mockup you provided looks like the datatable is nearly the entire screen --- why have it scroll at all? Why not just render a long table that makes the page scroll?

If the user has to scroll anyway, it is both simpler and more performant to just scroll the entire page than potentially thousands of elements within the page.

@jina @kaelig @stefsullrew @donnieberg

chriscorwin avatar Nov 03 '16 16:11 chriscorwin

@chriscorwin, approaching it like the screenshot allows the data table headings to stay visible at all times. It also allows the table to grow horizontally without pushing the buttons off the page. In instances where the data grows the user would have to scroll a lot to get back to the actions at the top of the page.

I noticed yesterday that SLDS has a “Fixed Header” variant now for 206 & 208.

https://latest-206.lightningdesignsystem.com/components/data-tables#flavor-fixed-header

CC @jina @kaelig @stefsullrew @donnieberg @jamin-hall

kwilloughby avatar Nov 04 '16 15:11 kwilloughby

@leiwlotus @chriscorwin is not actively working on DSR at this time. He was needed elsewhere.

I wonder if there is way to do a CSS transform via props that would allow the app to move the header row left and right based on an onScroll event in the app. We would still need static cell widths, but that seems like it would work correctly.

We'd have to do two React mount nodes (one in the header and one as the real table). Some kind of separateHeaderNode="#custom-header-mount"

and for the scrolling heading something like: horizontalHeaderOffset="-333px"

that would do transform: translate(-333px, 0px). works with https://latest-206.lightningdesignsystem.com/components/data-tables#flavor-fixed-header

There are still no fixed columns for checkboxes/actions, but that hasn't been asked for yet.

What do you think?

I'm unsure about the accessibility side of it--whether there's be duplicate headers for assistive tech or what.

interactivellama avatar Nov 11 '16 20:11 interactivellama

@interactivellama are you waiting on anything from me?

kwilloughby avatar Nov 30 '16 19:11 kwilloughby

No, another engineer is working on some markup changes. Then my plan was either to work on this myself or ask another. A few engineers are interested in DataTable. We are currently looking about a week out to get started on implementing this.

interactivellama avatar Nov 30 '16 19:11 interactivellama

@interactivellama @kwilloughby - Were you thinking about something like this? http://jsfiddle.net/bado/h0qr5g3h/ - We'd pass the scrollLeft around as a prop to update the transform, and use requestAnimationFrame to handle the scroll event in a more performant way. This would require the user to have fixed widths, though.

bado22 avatar Dec 13 '16 02:12 bado22

@bado22 That's exactly what I was thinking. I think column width is going to be needed if you want the table larger than the viewport. Are you planning on working on this? I'm updating the table markup today.

interactivellama avatar Dec 13 '16 15:12 interactivellama

@interactivellama Yes, I'll take this -- I'll have to work on it in my off hours, though. Are you updating the table markup based on #764 ?

bado22 avatar Dec 13 '16 15:12 bado22

Yes.

interactivellama avatar Dec 13 '16 15:12 interactivellama

@kevinparkerson

I think the CSS if present for this in SLDS, but that it's just hidden on the SLDS site.

You can get inspiration from this component too https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example

interactivellama avatar Nov 02 '18 19:11 interactivellama

@kevinparkerson Here is Alex B's code from 2016 https://github.com/interactivellama/design-system-react/tree/bado22-datatable-fixed-header

interactivellama avatar Nov 02 '18 21:11 interactivellama

@kevinparkerson

Notes from today

  • Consider supporting .slds-table_joined table section of SLDS that addes appropriate styling to a table header attached to a Page header. (Add example to Storybook)
  • Use .slds-table_header-fixed_container section of SLDS
  • Add onResize that consumers call and hook the document callback up to
  • Review SF Platform fixed header table implementation for confirmation and limitations of approach
  • Be aware of likelihood of adding column resizing in the future.

Please propose API before starting engineering work.

interactivellama avatar Nov 19 '18 23:11 interactivellama

@interactivellama here is all I was thinking:

/**
 * Set this to `true` for a data-table with fixed headers and scrolling columns / rows
 */
fixedHeader: PropTypes.bool,
/**
 * By default this function resizes the display headers when fixedHeader is `true`, but this behavior can be overridden
 */
onFixedHeaderResize: PropTypes.func,
/**
 * By default this function attaches/detaches listeners for window resize and tbody scrolling when fixedHeader is `true`, but this behavior can be overridden. Passes a boolean to specify whether listeners should be attached or detached.
 */
onToggleFixedHeaderListeners: PropTypes.func,

In the majority of cases, onFixedHeaderResize and onToggleFixedHeaderListeners would not be set by the app developer

kevinparkerson avatar Nov 27 '18 18:11 kevinparkerson