What's the best approach for creating filtered, sortable tables with an export function?

Jason D Jason D posted on 2024-07-01 05:22:12 UTC

Hey Everyone, I've been dabbling in Ruby on Rails now for a couple of years, (loving it!) and put together some pretty handy apps for both work and personal.

One thing I'm frustrated with at the moment is a "quick and simple",way of creating a table in a view; nicely formatted (tailwind or bootstrap) with a sort function, filtered and an export function (preferably to excel but CSV is fine). For example, when I need to create a custom report for a business unit.

Back in Rails 6 (with bootstrap) I used bootstrap-table (https://bootstrap-table.com/). This was great and just what I needed to quickly present a view of the data and give users the ability to sort it or export it for reporting purposes etc. 
Now with Rails 7 (importmaps), I'm stumped to get bootstrap-table working and a bit unsure how to configure the JS without any formal documentation.

What do people usually use for this type of problem? I'd love to hear suggestions and thoughts.

btw, I'm using import maps only because I like to try to stick with defaults where I can and think of upgrade paths for the future (e.g Rails 8).

David Kimura PRO said 11 days ago :
I've been meaning to cover something like this where when using importmaps and libraries that provide CSS. I think there are a few different approaches you could take. 

  • You could still rely on yarn and "double install" (via importmaps and yarn) the library. In your CSS, you can import the css libraries, but then use the importmaps as you normally would.
  • You can manually download the CSS file from the version that you're using. This should work if the library provides a minified CSS file. In your app/assets/stylesheets, I would create a vendor folder and place them in there.

I haven't done much research on either of these to determine the best route, but could be something worth exploring.

Login to Comment
Back to forums