webismymind / editablegrid

EditableGrid is an open source Javascript library aimed at turning HTML tables into advanced editable components. It focuses on simplicity: only a few lines of code are required to get your first table up and running.
http://www.editablegrid.net
Other
796 stars 271 forks source link

How are calculations done (pre-documentation question)? #4

Closed wysocki closed 11 years ago

wysocki commented 13 years ago

I see you haven't done any docs yet (when?) but there is a note at the bottom of the readme.txt referring to a "totals line". How can I perform column or row based calculations like a total?

webismymind commented 13 years ago

Currently, the documentation is limited to:

Remember that "EditableGrid is distributed in the hope that it will be useful"... but we have decided to take some time now to release the next version, mainly featuring a more complete documentation, but also some new features.

Now regarding your question...

The reference to a "total row" in the README file is only an example to explain the usefulness of the "EditableGrid.ignoreLastRow" property. There is currently no feature to automatically add a total row to the table. However, this is an interesting proposal and we certainly can include this feature in the next version!

Currently, if you want a total row (as we do in our applications), you have two possibilities:

  1. Add it in the data model of your table (either XML or HTML), which is easy if your data model is dynamically generated by a server-side script (PHP or other).
  2. Use the Javascript API to compute and add this row by yourself: use the functions getRowCount, getColumnCount and getValueAt to compute the total values then use addRow to append a row to the table (please refer to the API reference documention).

In both cases, you'll probably also need to make the "total" row read-only by redefining the "isEditable" callback, as well as exclude this row from the sorting by setting EditableGrid.ignoreLastRow = true.

Hope this helps and... keep posted!

webismymind commented 13 years ago

See https://github.com/webismymind/editablegrid/issues#issue/3/comment/591508 for more info on the isEditable callback.