Comments (2)
@hughkelsey I'm not sure why your example doesn't work (all I've done is read it), but if I recall correctly, I think I once did totals by doing a UNION query to add a row to the SQL results and giving Dossier a footer parameter of 1, so that it renders the last 1 row of SQL results as a footer.
Does that make sense?
I do like your idea of doing it in Ruby, though. If you want to debug what's happening in your example, bundle open dossier
will let you add puts
statements or whatever, and gem pristine dossier
will clean up for you when you're done.
from dossier.
In case anyone faces this issue, the problem seems to be that report.results
gets called 4 times in the report show, which adds a row each time and recalculates the sum for all previous rows. I found two ways to get around the issue:
- Call
report.results
only once in the report show, save the result in a temp variable- res = report.results
, and use that to render the report. - Use an if statement to stop adding rows once the first one was added
def results
original_results = super
unless original_results.rows.last[0] == 'Total'
total_value = original_results.rows.map {|row| row.last.to_f}.sum.round(2)
original_results.rows << ['Total', total_value.to_s]
end
original_results
end
Neither of those two solutions seems particularly elegant. I tried using report.results.body
and report.results.footers
to do the calculation instead but that didn't work since the gem automatically assigns the last N rows as footers then puts whatever is left in the body.
It could be worth considering a way to add N empty footers which the user can then fill as needed instead of splitting one dataset between body and footers.
from dossier.
Related Issues (20)
- Pagination question HOT 3
- Connection not working on production
- How to specify which view to use? HOT 1
- Grouped information HOT 4
- Rails 4.2 ActionController::Responder Integration HOT 2
- Can you namespace the default dossier route? HOT 3
- How can I select a database column without displaying it as its own report column? HOT 3
- Question: Is it possible to pass my own arguments into the constructor for a report? HOT 4
- What commands are needed to get this up and running?
- Return more than one query to report HOT 2
- Passing options to Report from Controller HOT 1
- CSV Report Formatting HOT 1
- MultiTenant App with Dossier
- crosstab example
- Derived data columns
- HAML dependency HOT 1
- CSV not working on some reports HOT 1
- JSON/CSV issues with display_column?
- Does not work with Rails 6 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dossier.