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

style solution for collapsing tables to cards #350

Open
derekeder opened this issue Sep 22, 2023 · 4 comments
Open

style solution for collapsing tables to cards #350

derekeder opened this issue Sep 22, 2023 · 4 comments
Assignees

Comments

@derekeder
Copy link
Member

derekeder commented Sep 22, 2023

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
Copy link
Contributor

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

@derekeder
Copy link
Member Author

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
Copy link
Contributor

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

@derekeder
Copy link
Member Author

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

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

No branches or pull requests

2 participants