Posted to tcl by colin at Tue Jan 04 01:38:55 GMT 2011view raw

  1. # dict2table - convert dict into sortable HTML table
  2. # provisional new version
  3. proc dict2table {dict header {footer {}} {tag ""}} {
  4. set row 0
  5. return [<table> class sortable summary "" {*}[If {$tag ne ""} { class $tag }] [subst {
  6. [<thead> [<tr> [Foreach t $header {
  7. [<th> class $t [string totitle $t]]
  8. }]]]
  9. [If {$footer ne {}} {
  10. [<tfoot> [<tr> [Foreach t $footer {[<th> [string totitle $t]]}]]]
  11. } else {
  12. [<tfoot> [<tr> [Foreach t $header {[<th> [string totitle $t]]}]]]
  13. }]
  14. [<tbody> [Foreach {k v} $dict {
  15. [<tr> class [If {[incr row] % 2} even else odd] \
  16. [Foreach th $header {
  17. [If {[dict exists $v $th]} {
  18. [<td> class $th [dict get $v $th]]
  19. } else {
  20. [<td> {}]
  21. }]
  22. }]]
  23. }]]
  24. }]]
  25. }