Pagination question
Closed this issue · 3 comments
Is it possible to paginate these reports or use the will-paginate gem in conjunction with them? If so, do you have an example of how to do this? Thanks.
Hey @jackiejohnston
At the moment we haven't supported pagination because it requires additional queries to determine building the pagination (queries based off of your original). You could setup pagination manually by passing the options into your report. Aka: /reports/fancy?options[page]=2
and then inject the appropriate limit and offset based off of options[:page]
.
I'd be happy to provide additional clarification if you would like. Feel free to let me know if you'd like me to try and setup an example of this. If you get something working and would like to add a section to the readme, that would also be awesome!
Thanks!
Thanks @adamhunter, I think I can make that work the next time I use your gem. Unfortunately I spent part of my day rewriting some reports without your gem because my boss was in a hurry to get it done. I really hated this because it wasn't nearly as easy as using your gem! So thank you for a cool gem. I'm sure I'll be using it again, and trying your idea with the option parameters to paginate.
@adamhunter if you decide to add pagination support, I'd be happy to pair with you on it, because I'd like to have that feature.
My first thought is that if a report defined an additional .count_sql
method, we could use that to figure out the total number of records. Users could define both .count_sql
and .sql
in terms of a .base_query
method; eg, if they were using ActiveRecord, .count_sql
would be like base_query.select("COUNT(*)").to_sql
and .sql
would be like base_query.limit(limit).offset(offset).to_sql
.
...except that you probably want your CSV files NOT to use the limit and offset, so maybe you need a third method...
My current workaround for big reports is to not offer HTML at all; only a CSV download. Eg,
# app/views/dossier/reports/show.html.haml
%h2= report.formatted_title
- if report.results.any?
= link_to 'Download CSV', formatted_dossier_report_path('csv', report), class: 'download-csv'
- else
There are no results for the criteria given