Page MenuHomePhabricator

jquery.tablesorter: Breaking tfoot with rowspans
Open, Needs TriagePublic

Description

When you apply "sortable" to a table (and the jquery.sorted library is loaded), it checks the last table to see if it doesn't contain a "td" element. However, this breaks a rowspan attribute, and causes it to not carry over as it parses to a tfoot rather than in the tbody.

Revisions and Commits

rMW MediaWiki

Event Timeline

Cblair91 raised the priority of this task from to Needs Triage.
Cblair91 updated the task description. (Show Details)
Cblair91 added a subscriber: Cblair91.

Is this a library that Wikimedia uses somewhere?

Cblair91 renamed this task from jquery.sorted.js tfoot with rowspans to jquery.tablesorter.js: tfoot with rowspans.Oct 4 2015, 1:39 PM
Cblair91 set Security to None.
for ( i = len - 1; i >= 0; i-- ) {
	if ( $( $rows[ i ] ).children( 'td' ).length ) {
		break;
	}
	$tfoot.prepend( $( $rows[ i ] ) );
}

Changes to:

var tfootAdditions = [], rowspan, ii;
for ( i = len - 1; i >= 0; i-- ) {
	if ( $( $rows[ i ] ).children( 'td' ).length ) {
		rowspanNum = $( $rows[ i ] ).children( 'td' ).attr( 'rowspan' );
		if ( rowspan !== undefined ) {
			for ( ii = parseInt( rowspan ); ii < parseInt( rowspan ).length; ii++ ) {
				if ( tfootAdditions.indexOf( i + parseInt( rowspan ) ) !== -1 ) {
					tfootAdditions.splice( tfootAdditions.indexOf( i + parseInt( rowspan ) ) );
				}
			}
		}
		continue;
	}
	tfootAdditions.push( i );
}
for ( i = 0; i < tfootAdditions.length; i++ ) {
	$tfoot.prepend( $( $rows[ i ] ) );
}

Probably the hackiest way about the problem, but should resolve it :P

Would you like to submit a patch to gerrit?

I think it's best that a developer takes a look, since the code is hacky and could be majorly improved. =]

That's the point of Gerrit, not Phabricator

@Cblair91: Thanks for taking a look at the code!

You are very welcome to use developer access to submit this as a Git branch directly into Gerrit.
If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again!

Change 243521 had a related patch set uploaded (by Gerrit Patch Uploader):
Fixes T114604

https://gerrit.wikimedia.org/r/243521

Woops, can somebody close that patch. Forgot a comma =]

Change 243522 had a related patch set uploaded (by Gerrit Patch Uploader):
Fixes T114604

https://gerrit.wikimedia.org/r/243522

-sigh- 3rd patch fixes all JSLint issues. Should do patches in future when not sleepy.

Change 243521 abandoned by Alex Monk:
Fixes T114604

Reason:
-> I4e6ed349

https://gerrit.wikimedia.org/r/243521

Change 243525 had a related patch set uploaded (by Gerrit Patch Uploader):
Fixes T114604

https://gerrit.wikimedia.org/r/243525

Please stop uploading new commits. Just amend your existing commit.

Change 243522 abandoned by Alex Monk:
Fixes T114604

Reason:
-> Ibe8c500e

https://gerrit.wikimedia.org/r/243522

Can't do that using the patcher :(

@Cblair91: Amending is covered in https://www.mediawiki.org/wiki/Gerrit/Tutorial#Amending_a_change_.28your_own_or_someone_else.27s.29 but no idea if Gerrit Patch Uploader also supports that. Sorry for any confusion I might have created. :-(

The README file for it says "To upload an update to an existing patch, copy the Change-Id line from that changeset, and add it to the bottom of your commit message.", so I'm pretty sure that's not true. But you don't need to use that thing anyway.

Sadly, I do not have access to GIT at this time. If somebody else could ammend the commit message, that would be great (Y)

To be honest the commit message part can be done from the gerrit web interface.

Oh didn't notice that until now =] Thanks. And commit message updated.

Change 243525 had a related patch set uploaded (by TheDJ):
jquery.tablesorter: Support rowspan in tfoot

https://gerrit.wikimedia.org/r/243525

Where is this a problem right now ? theoretical, practical ? In wikicode, or in an extension ?

Also, will need a qunit testcase to verify that this will not regress at some point in the future.

Practical. A sortable table exists on one of my wikis, and is causing this issue currently. And yes, on a page using wikicode =]

Please give the EXACT piece of code so that the patch can be verified for correctness.

{| class="wikitable sortable"
! Month
! Content
|-
! January
| rowspan="2" | '''Added some stuff.'''
|-
! February
|}

The following code will change "February" into the table footer, rather than allowing the rowspan to carry into it.

This doesn't look correct. The point of the code is that any row containing a <td> disqualifies the row for inclusion into the tfoot.

Instead, it should probably keep track of the length of previously selected lines (n: 1 th, n-1: 1th + 1td) and then just fully bail tfoot emulation in such complex cases.

TheDJ reopened this task as Open.EditedApr 28 2016, 2:18 PM

Accidental ticket closure. (due to import of repo and commitmessage actions being triggered ?)

Change 291342 had a related patch set uploaded (by MatthiasDD):
jquery.tablesorter: Rowspan td until footer row

https://gerrit.wikimedia.org/r/291342

Change 692110 had a related patch set uploaded (by BrandonXLF; author: BrandonXLF):

[mediawiki/core@master] jquery.tablesort: Keep track of rowspans when adding to tfoot

https://gerrit.wikimedia.org/r/692110

Krinkle renamed this task from jquery.tablesorter.js: tfoot with rowspans to jquery.tablesorter: Breaking tfoot with rowspans.May 18 2021, 8:04 PM