datamade / how-to

📚 Doing all sorts of things, the DataMade way
MIT License
89 stars 12 forks source link

style solution for collapsing tables to cards #350

Open derekeder opened 1 year ago

derekeder commented 1 year ago

We have a lot of sites that make use of showing data in a table format. However, on mobile, the horizontal space is limited and bootstrap's default solution with table-responsive (https://getbootstrap.com/docs/5.3/content/tables/#responsive-tables) only allows for horizontal scrolling.

In Datasette, they have a nice solution to this with css that make the table rows display as cards:

https://puddle.bunkum.us/chicago_council-fb92b83/voteevent

desktop: Screenshot 2023-09-22 at 3 54 09 PM

mobile: Screenshot 2023-09-22 at 3 54 20 PM

The HTML markup doesn't change, but at a breakpoint the table css does: https://github.com/simonw/datasette/blob/main/datasette/templates/row.html#L8-L11

@smcalilly do you do something like this for CCFP? I'd like to document a tool or some CSS that we can repurpose for our sites when we need it.

smcalilly commented 1 year ago

@derekeder +1, this would be very useful. I just looked at CCFP and we're using the bootstrap horizontal scroll.

derekeder commented 1 year ago

I implemented a version of this for Councilmatic. We could use this in other places with about 40 lines of css and a new span added to each table row. Its on Bootstrap 3, but could easily be adapted to Bootstrap 4 or 5. The biggest difference is the difference in breakpoints and utility classes in the different versions.

Table of data on desktop: Screenshot 2023-09-29 at 2 52 01 PM

Same table rendered as cards on mobile: Screenshot 2023-09-29 at 2 52 14 PM

smcalilly commented 1 year ago

@derekeder wants to try this in another project with Bootstrap 5.

derekeder commented 1 year ago

when its ready, i'll document in the Bootstrap section of the how-to docs