Currently the datasource HTML table parser only processes rows in the table body. Also the datatable widget only uses a table body (tbody) to display the rows in the recordset.
If I am doing progressive enhancement of a table that includes e.g. subtotals & totals in a footer (tfoot) section, I have to reproduce these programmatically after creating the datatable instance,
using appropriate DOM manipulation. Asides from the amount of code this requires, it is also awkward to reproduce the appropriate CSS classes to let it fit in with the look of the rest of the table.
To make this easier, I suggest the following enhancements:
- add methods to add/delete/update rows in the footer section, similar to the existing addRow[s]/deleteRow[s]/update[Row|Cell] for the body. Presumably a second recordset would be needed to store the
footer records. The methods would automatically add cells, liner divs, the various CSS classes e.g. yui-dt-col-*, and use the specified formatter for the column (unless told not to? e.g. it may not
be desirable to use formatLink on a TOTAL label) Corresponding formatFooterRow etc. events might be needed, unless the existing ones could be reused?
- enhance the datasource table parser to extract records from the tfoot as well as the body. This could either return a separate recordset (in the meta field?) or perhaps additional records in (at
the end of?) the existing record set if there were some way to differentiate them. The datatable's constructor could then use these to initially populate the footer section.
- alternatively, a second version of the HTML parser could be created that processes just the tfoot instead of the tbody. Two datasources could then be used to process the same table, to obtain a
record set for each section. An additional constructor for the datatable could be passed both datasources (or the footer one could be optionally passed in the options).
- a way to specify (in the columns definitions, perhaps?) whether a given footer cell should be a td or a th would be useful (I usually use th for the TOTAL text and td for the corresponding value).
- ultimately, it would be nice to be able to somehow specify a footer cell should be automatically updated when the values in the column change, but that gets complicated for anything other than a
single row with a grand total. So initially it can be left for the user to do programmatically in the relevant "cell updated" event. An example of this in the docs would be useful, though.