Git Product home page Git Product logo

Comments (2)

nathanl avatar nathanl commented on September 26, 2024

@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.

ayaman avatar ayaman commented on September 26, 2024

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:

  1. 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.
  2. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.