Skip to content

Commit

Permalink
Item8303: add links to the right rows for sorting
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@8446 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Aug 9, 2010
1 parent 7beb1e4 commit 31bfcf0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
6 changes: 6 additions & 0 deletions TablePlugin/data/System/TablePlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ Click on column heading text to sort by a column. Initial column will be sorted
* Number is digits, with optional decimal point
* Otherwise treated as text

If you specify =headerrows=, then the row with the sort links is the row
closest to the data (the last row in the header). If you do not specify
=headerrows=, the first row that has a heading in the first column is the
sort row. To sort by the first _footer_ row, set =headerrows="0"=.

---++++ Sorting example
%TABLE{databg="#ffc" databgsorted="#fc3" headerbg="#903" headerbgsorted="#600" initsort="1"}%
| *Number* | *Decimal* | *Alpha* | *Date* |
Expand Down Expand Up @@ -173,6 +178,7 @@ Sort icons in the header are read from System.DocumentGraphics.
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- specify latest version first -->&nbsp; |
| 9 Aug 2010 | 1.125: Crawford Currie: Item8303: fixed sorting with multiple headers |
| 31 Jul 2010 | 1.124: Arthur Clemens: Added attribute =inlinemarkup= to optionally add HTML markup for better copy/pasting. |
| 05 Apr 2010 | 1.123: New default colors. |
| 13 Mar 2010 | 1.122: Arthur Clemens: Fixed sorting of columns with mixed data types: numbers, dates, strings, empty cells. |
Expand Down
2 changes: 1 addition & 1 deletion TablePlugin/lib/Foswiki/Plugins/TablePlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use strict;
use warnings;

our $VERSION = '$Rev$';
our $RELEASE = '1.124';
our $RELEASE = '1.125';
our $SHORTDESCRIPTION =
'Control attributes of tables and sorting of table columns';
our $NO_PREFS_IN_TOPIC = 1;
Expand Down
21 changes: 11 additions & 10 deletions TablePlugin/lib/Foswiki/Plugins/TablePlugin/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1450,8 +1450,9 @@ sub emitTable {
my $singleIndent = "\n\t";
my $doubleIndent = "\n\t\t";
my $tripleIndent = "\n\t\t\t";
# Only *one* row of the table has sort links, and it will either
# be the last row in the header or the first row in the footer.
my $sortLinksWritten = 0;
my $writingSortLinks = 0;

foreach my $row (@curTable) {
my $rowtext = '';
Expand All @@ -1461,6 +1462,7 @@ sub emitTable {
# update the data color count
my $headerCellCount = 0;
my $numberOfCols = scalar(@$row);
my $writingSortLinks = 0;

foreach my $fcell (@$row) {

Expand Down Expand Up @@ -1554,10 +1556,10 @@ sub emitTable {

# END html attribute

# just allow this table to be sorted.
# if ( $sortThisTable
# && $rowCount == $combinedTableAttrs->{headerrows} - 1 )
if ( $sortThisTable && !$sortLinksWritten ) {
if ( $sortThisTable
&& (!$combinedTableAttrs->{headerrows}
|| $rowCount == $combinedTableAttrs->{headerrows} - 1)
&& ($writingSortLinks || !$sortLinksWritten)) {
$writingSortLinks = 1;
my $linkAttributes = {
href => $url
Expand Down Expand Up @@ -1630,6 +1632,10 @@ sub emitTable {
$attr->{class} = _appendSortedCssClass( $attr->{class} );
}

if ($writingSortLinks) {
$sortLinksWritten = 1;
}

my $isLastRow = ( $rowCount == $numberOfRows - 1 );
if ( $attr->{rowspan} ) {
$isLastRow =
Expand All @@ -1655,11 +1661,6 @@ sub emitTable {
use strict 'refs';
} # foreach my $fcell ( @$row )

if ($writingSortLinks) {
$writingSortLinks = 0;
$sortLinksWritten = 1;
}

# assign css class names to tr
# based on settings: dataBg, dataBgSorted
my $trClassName = '';
Expand Down
10 changes: 5 additions & 5 deletions TablePlugin/test/unit/TablePlugin/TablePluginTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ sub test_doubleTheadandTfootTableusingTablePlugin {
<table id="table$this->{test_topic}$tableCount" class="foswikiTable" rules="none" border="1">
<thead>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" title="Sort by this column">a</a> </th>
<th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" title="Sort by this column">b</a> </th>
<th class="foswikiTableCol0 foswikiFirstCol"> a </th>
<th class="foswikiTableCol1 foswikiLastCol"> b </th>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> c </th>
<th class="foswikiTableCol1 foswikiLastCol"> c </th>
<th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" title="Sort by this column">c</a> </th>
<th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" title="Sort by this column">d</a> </th>
</tr>
</thead>
<tfoot>
Expand All @@ -254,7 +254,7 @@ EXPECTED
my $actual = <<ACTUAL;
%TABLE{headerrows="2" footerrows="1"}%
| *a* | *b* |
| *c* | *c* |
| *c* | *d* |
| 2 | 3 |
| *ok* | *bad* |
ACTUAL
Expand Down

0 comments on commit 31bfcf0

Please sign in to comment.