New HTML style features for tables

Bill Gribble grib@gnumatic.com
Fri, 9 Mar 2001 10:09:13 -0600


Dave: after our IRC discussion I added a few new things to the
html-table API to allow reports to assign semantic tags like "total",
"subtotal", "summary-row" etc to table cells and rows and have that
map to a different rendering style that can be set at the style-sheet
level.  I'll be sending you the patch for this today after I test it a
bit.

To get an individual table cell to render with a different style, you
need to create the cell with the new function
gnc:make-html-table-cell/markup.  The first argument is the markup tag
you want to use.  For example, if you want all "grand-total" table
cells to be rendered with a background color of 0xff00ff, you'd put
this in the style sheet definition:

  (gnc:html-style-sheet-set-style! 
   ss "grand-total" 
   'tag "td"
   'attribute (list "bgcolor" "0xff00ff"))

  Then in the report, you'd create the cell like so:

  (gnc:make-html-table-cell/markup "grand-total" 256.75) 
 
It's important that you put the 'tag "td" in the style sheet or you
will end up with a very strange looking table :)

The table-cell API for doing this is just:

  (gnc:make-html-table-cell/markup markup . objects)  
    Make a table cell with "objects" as content and "markup" as 
    the cell markup rather than the default "td"

  (gnc:make-html-table-cell/size/markup rowspan colspan markup . objects)
    Make a table cell with given rowspan/colspan and markup

You can set semantic styles for new rows that you are adding to the
table in a similar way, replacing the default "tr" markup with
whatever you want:

  (gnc:html-table-append-row/markup! table row-data markup)
  (gnc:html-table-prepend-row/markup! table row-data markup)

You can get and set the markup for individual rows by number: 

  (gnc:html-table-row-markup table row-num)
  (gnc:html-table-set-row-markup! table row-num markup)

gnc:html-table-row-markup returns #f if no markup has been set for
that row, in which case the default "tr" will be used.

Again, you just define the style in the style sheet:

  (gnc:html-style-sheet-set-style! 
    ss "summary-row"
    'tag "tr"
    'attribute (list "bgcolor" "0xff00ff"))

Make sure you put 'tag "tr" in the definition.

Hope this does what you wanted.  Since styles have fairly limited
control at this point (all you can really do is set attributes and
fonts) it isn't the all-singing all-dancing solution but I think it
will do 90% of what we need and it's about 30 lines of code :)

b.g.