Posted to tcl by colin at Tue Jan 04 01:38:55 GMT 2011view pretty
# dict2table - convert dict into sortable HTML table # provisional new version proc dict2table {dict header {footer {}} {tag ""}} { set row 0 return [<table> class sortable summary "" {*}[If {$tag ne ""} { class $tag }] [subst { [<thead> [<tr> [Foreach t $header { [<th> class $t [string totitle $t]] }]]] [If {$footer ne {}} { [<tfoot> [<tr> [Foreach t $footer {[<th> [string totitle $t]]}]]] } else { [<tfoot> [<tr> [Foreach t $header {[<th> [string totitle $t]]}]]] }] [<tbody> [Foreach {k v} $dict { [<tr> class [If {[incr row] % 2} even else odd] \ [Foreach th $header { [If {[dict exists $v $th]} { [<td> class $th [dict get $v $th]] } else { [<td> {}] }] }]] }]] }]] }