3 $sortkeys => 'ts_sortkeys'
14 % my $sortfn= "ts_sort__$table";
15 function <% $sortfn %>(compar) {
16 debug('sorting compar='+compar);
17 var table= document.getElementById('<% $table %>');
18 var firstrow= table.getElementsByTagName('tr').item(0);
19 var tbody= firstrow.parentNode
20 var rows= tbody.childNodes
21 var newrows= new Array;
22 for (var rowix=0; rowix < rows.length; rowix++) {
23 var row= rows.item(rowix);
24 debug('process row '+rowix+' [[ '+row+' ]] id='+row.id)
25 if (!row.id) continue;
26 if (row.tagName != 'TR') continue;
30 for (var rowix=0; rowix < newrows.length; rowix++) {
31 var row= newrows[rowix];
32 debug('add row '+rowix+' [[ '+row+' ]]');
33 tbody.appendChild(row);
38 % foreach my $cix (0..$#$cols) {
39 % my $col= $cols->[$cix];
41 % next if $col->{NoSort};
43 % my $mapfn= "ts_compar${cix}_map__$table";
44 function <% $mapfn %>(rowelement) {
45 var rowid = rowelement.id;
46 % if ($col->{SortKey}) {
47 var sk = <% $col->{SortKey} %>;
48 debug('map rowid='+rowid+' sk='+sk);
51 return <% $sortkeys %>[<% $cix %>][rowid];
55 % my $comparefn= "ts_compar${cix}_cmp0__$table";
56 function <% $comparefn %>(a,b) {
57 var a_key = <% $mapfn %>(a);
58 var b_key = <% $mapfn %>(b);
59 % if ($col->{Numeric}) {
62 if (a_key < b_key) return -1;
63 if (a_key > b_key) return +1;
68 % foreach my $reverse (qw(0 1)) {
69 % my $tcomparefn= "ts_compar${cix}_cmp${reverse}__$table";
71 % next unless $col->{DoReverse};
72 function <% $tcomparefn %>(a,b) { return -<% $comparefn %>(a,b); }
74 % $thhtml .= "<a href=\"javascript:$sortfn($tcomparefn)\">".
75 % ($reverse ? '∨' : '∧'). '</a>';
77 % if (length $thhtml) {
78 % $add_heads{$cix}= $thhtml;
82 function ts_onload__<% $table %>() {
83 var ts_add_heads= <% to_json_protecttags(\%add_heads) %>;
84 var table= document.getElementById('<% $table %>');
85 var firstth= table.getElementsByTagName('th').item(0);
86 var thlist= firstth.parentNode.getElementsByTagName('th');
87 debug('thlist='+thlist);
88 debug('thlist.item(2)=' + thlist.item(2));
89 for (var cix in ts_add_heads) {
90 var ah = ts_add_heads[cix];
91 debug('appending to cix='+cix+' ah='+ah);
92 thlist.item(cix).innerHTML += ah;