Skip to content

Commit 31bfcf0

Browse files
CrawfordCurrieCrawfordCurrie
authored andcommitted
Item8303: add links to the right rows for sorting
git-svn-id: http://svn.foswiki.org/trunk@8446 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
1 parent 7beb1e4 commit 31bfcf0

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

TablePlugin/data/System/TablePlugin.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ Click on column heading text to sort by a column. Initial column will be sorted
8080
* Number is digits, with optional decimal point
8181
* Otherwise treated as text
8282

83+
If you specify =headerrows=, then the row with the sort links is the row
84+
closest to the data (the last row in the header). If you do not specify
85+
=headerrows=, the first row that has a heading in the first column is the
86+
sort row. To sort by the first _footer_ row, set =headerrows="0"=.
87+
8388
---++++ Sorting example
8489
%TABLE{databg="#ffc" databgsorted="#fc3" headerbg="#903" headerbgsorted="#600" initsort="1"}%
8590
| *Number* | *Decimal* | *Alpha* | *Date* |
@@ -173,6 +178,7 @@ Sort icons in the header are read from System.DocumentGraphics.
173178
| Version: | %$VERSION% |
174179
| Release: | %$RELEASE% |
175180
| Change History: | <!-- specify latest version first -->&nbsp; |
181+
| 9 Aug 2010 | 1.125: Crawford Currie: Item8303: fixed sorting with multiple headers |
176182
| 31 Jul 2010 | 1.124: Arthur Clemens: Added attribute =inlinemarkup= to optionally add HTML markup for better copy/pasting. |
177183
| 05 Apr 2010 | 1.123: New default colors. |
178184
| 13 Mar 2010 | 1.122: Arthur Clemens: Fixed sorting of columns with mixed data types: numbers, dates, strings, empty cells. |

TablePlugin/lib/Foswiki/Plugins/TablePlugin.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use strict;
99
use warnings;
1010

1111
our $VERSION = '$Rev$';
12-
our $RELEASE = '1.124';
12+
our $RELEASE = '1.125';
1313
our $SHORTDESCRIPTION =
1414
'Control attributes of tables and sorting of table columns';
1515
our $NO_PREFS_IN_TOPIC = 1;

TablePlugin/lib/Foswiki/Plugins/TablePlugin/Core.pm

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,9 @@ sub emitTable {
14501450
my $singleIndent = "\n\t";
14511451
my $doubleIndent = "\n\t\t";
14521452
my $tripleIndent = "\n\t\t\t";
1453+
# Only *one* row of the table has sort links, and it will either
1454+
# be the last row in the header or the first row in the footer.
14531455
my $sortLinksWritten = 0;
1454-
my $writingSortLinks = 0;
14551456

14561457
foreach my $row (@curTable) {
14571458
my $rowtext = '';
@@ -1461,6 +1462,7 @@ sub emitTable {
14611462
# update the data color count
14621463
my $headerCellCount = 0;
14631464
my $numberOfCols = scalar(@$row);
1465+
my $writingSortLinks = 0;
14641466

14651467
foreach my $fcell (@$row) {
14661468

@@ -1554,10 +1556,10 @@ sub emitTable {
15541556

15551557
# END html attribute
15561558

1557-
# just allow this table to be sorted.
1558-
# if ( $sortThisTable
1559-
# && $rowCount == $combinedTableAttrs->{headerrows} - 1 )
1560-
if ( $sortThisTable && !$sortLinksWritten ) {
1559+
if ( $sortThisTable
1560+
&& (!$combinedTableAttrs->{headerrows}
1561+
|| $rowCount == $combinedTableAttrs->{headerrows} - 1)
1562+
&& ($writingSortLinks || !$sortLinksWritten)) {
15611563
$writingSortLinks = 1;
15621564
my $linkAttributes = {
15631565
href => $url
@@ -1630,6 +1632,10 @@ sub emitTable {
16301632
$attr->{class} = _appendSortedCssClass( $attr->{class} );
16311633
}
16321634

1635+
if ($writingSortLinks) {
1636+
$sortLinksWritten = 1;
1637+
}
1638+
16331639
my $isLastRow = ( $rowCount == $numberOfRows - 1 );
16341640
if ( $attr->{rowspan} ) {
16351641
$isLastRow =
@@ -1655,11 +1661,6 @@ sub emitTable {
16551661
use strict 'refs';
16561662
} # foreach my $fcell ( @$row )
16571663

1658-
if ($writingSortLinks) {
1659-
$writingSortLinks = 0;
1660-
$sortLinksWritten = 1;
1661-
}
1662-
16631664
# assign css class names to tr
16641665
# based on settings: dataBg, dataBgSorted
16651666
my $trClassName = '';

TablePlugin/test/unit/TablePlugin/TablePluginTests.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ sub test_doubleTheadandTfootTableusingTablePlugin {
229229
<table id="table$this->{test_topic}$tableCount" class="foswikiTable" rules="none" border="1">
230230
<thead>
231231
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
232-
<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>
233-
<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>
232+
<th class="foswikiTableCol0 foswikiFirstCol"> a </th>
233+
<th class="foswikiTableCol1 foswikiLastCol"> b </th>
234234
</tr>
235235
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
236-
<th class="foswikiTableCol0 foswikiFirstCol"> c </th>
237-
<th class="foswikiTableCol1 foswikiLastCol"> c </th>
236+
<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>
237+
<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>
238238
</tr>
239239
</thead>
240240
<tfoot>
@@ -254,7 +254,7 @@ EXPECTED
254254
my $actual = <<ACTUAL;
255255
%TABLE{headerrows="2" footerrows="1"}%
256256
| *a* | *b* |
257-
| *c* | *c* |
257+
| *c* | *d* |
258258
| 2 | 3 |
259259
| *ok* | *bad* |
260260
ACTUAL

0 commit comments

Comments
 (0)