.. _totals:

========
 Totals
========

Numeric columns of a Table have the option to show totals and
subtotals. Subtotals are determined by brake fields/functions. This may be
done interactively from the column menu or from code. The following example
is very stupid but... you get the feeling!::

    t = SqlTable('movie', dbproxy=db, order_by='director_id')
    t.totals.add_break('director_id')
    t.totals.add_total('year')


.. image:: ../img/totals.png
    
  
personalization and colors
---------------------------

Totals are generated by a class ``sqlkit.widgets.table.totals.Totals`` that
can be inherited and modified to set different total behavior.

The colors are defined in a class in the same module ``TotalObj`` whose
method ``set_value_and_colors`` can be used to personalize colors and markup
of the cell.

dates
------

Since date breaks are probably very common a function makes it easy to
brake on dates.

totals... with no totals!
--------------------------

If you only need subtotals and not totals you can prevent totals using
option ``hide_total`` when declaring the column to sum.

API
---

.. module:: sqlkit.widgets.table.totals

.. autoclass:: Totals
   :members: add_total, add_break, add_date_break, compute

.. autoclass:: TotalObj
   :members:

   
