chiark / gitweb /
Sortable commodity price table
[ypp-sc-tools.db-test.git] / yarrg / web / tabsort
index e690ac8df740d2535ecc56425452e79ab4463305..ad25f86b9ab981d58ed2e740cd91cc9d7d6ba23e 100644 (file)
@@ -38,6 +38,7 @@
 <%args>
 $table => 'ts_table'
 $sortkeys => 'ts_sortkeys'
+$throw => undef
 $cols
 </%args>
 
@@ -60,6 +61,9 @@ function <% $sortfn %>(compar) {
     var row= rows.item(rowix);
     debug('process row '+rowix+' [[ '+row+' ]] id='+row.id)
     if (!row.id) continue;
+%      if (defined $throw) {
+    if (row.id == '<% $throw %>') continue;
+%      }
     if (row.tagName != 'TR') continue;
     newrows.push(row);
   }
@@ -83,7 +87,12 @@ function <% $mapfn %>(rowelement) {
 %      if ($col->{SortKey}) {
   return <% $col->{SortKey} %>;
 %      } else {
-  return <% $sortkeys %>[<% $cix %>][rowid];
+%              my $sk= "$sortkeys"."[$cix][rowid]";
+%              if ($col->{MapFn}) {
+  return <% $col->{MapFn} %>(<% $sk %>);
+%              } else {
+  return <% $sk %>;
+%              }
 %      }
 }
 
@@ -116,8 +125,8 @@ function <% $tcomparefn %>(a,b) { return -<% $comparefn %>(a,b); }
 
 function ts_onload__<% $table %>() {
   var ts_add_heads= <% to_json_protecttags(\%add_heads) %>;
-  var table= document.getElementById('<% $table %>');
-  var firstth= table.getElementsByTagName('th').item(0);
+  var ctr= document.getElementById('<% defined($throw) ? $throw : $table %>');
+  var firstth= ctr.getElementsByTagName('th').item(0);
   var thlist= firstth.parentNode.getElementsByTagName('th');
   debug('thlist='+thlist);
   debug('thlist.item(2)=' + thlist.item(2));