2 var header
= [ 'Planet', 'Radius (km)' ],
5 mercury
= [ 'Mercury', '2439.7' ],
6 venus
= [ 'Venus', '6051.8' ],
7 earth
= [ 'Earth', '6371.0' ],
8 mars
= [ 'Mars', '3390.0' ],
9 jupiter
= [ 'Jupiter', '69911' ],
10 saturn
= [ 'Saturn', '58232' ],
11 planets
= [ mercury
, venus
, earth
, mars
, jupiter
, saturn
],
12 planetsAscName
= [ earth
, jupiter
, mars
, mercury
, saturn
, venus
],
13 planetsAscRadius
= [ mercury
, mars
, venus
, earth
, saturn
, jupiter
],
25 simple
= [ a2
, b3
, a1
, a3
, b2
, b1
],
26 simpleAsc
= [ a1
, a2
, a3
, b1
, b2
, b3
],
27 simpleDescasc
= [ b1
, b2
, b3
, a1
, a2
, a3
],
30 header4
= [ 'column1a', 'column1b', 'column1c', 'column2' ],
31 aaa1
= [ 'A', 'A', 'A', '1' ],
32 aab5
= [ 'A', 'A', 'B', '5' ],
33 abc3
= [ 'A', 'B', 'C', '3' ],
34 bbc2
= [ 'B', 'B', 'C', '2' ],
35 caa4
= [ 'C', 'A', 'A', '4' ],
36 colspanInitial
= [ aab5
, aaa1
, abc3
, bbc2
, caa4
],
40 // Some randomly generated fake IPs
44 [ '204.204.132.158' ],
51 // Sort order should go octet by octet
58 [ '204.204.132.158' ],
77 umlautWordsSortedEn
= [
91 umlautWordsSortedSv
= [
102 [ 'ä' ], // ä sorts after z in Swedish
106 // Data set "digraph"
115 digraphWordsSorted
= [
125 [ 'January, 19 2010' ],
129 [ 'December 12 \'10' ]
135 [ 'January, 19 2010' ],
136 [ 'December 12 \'10' ]
155 // Commas sort after dots
156 // Not intentional but test to detect changes
177 correctDateSorting1
= [
178 [ '01 January 2010' ],
179 [ '05 February 2010' ],
180 [ '16 January 2010' ]
182 correctDateSortingSorted1
= [
183 [ '01 January 2010' ],
184 [ '16 January 2010' ],
185 [ '05 February 2010' ]
188 correctDateSorting2
= [
189 [ 'January 01 2010' ],
190 [ 'February 05 2010' ],
191 [ 'January 16 2010' ]
193 correctDateSortingSorted2
= [
194 [ 'January 01 2010' ],
195 [ 'January 16 2010' ],
196 [ 'February 05 2010' ]
200 [ '2009-12-25T12:30:45.001Z' ],
203 [ '2009-12-25T12:30:45' ],
204 [ '2009-12-25T12:30:45.111' ],
205 [ '2009-12-25T12:30:45+01:00' ]
207 isoDateSortingSorted
= [
209 [ '2009-12-25T12:30:45+01:00' ],
210 [ '2009-12-25T12:30:45' ],
211 [ '2009-12-25T12:30:45.001Z' ],
212 [ '2009-12-25T12:30:45.111' ],
217 QUnit
.module( 'jquery.tablesorter', QUnit
.newMwEnvironment( {
219 this.liveMonths
= mw
.language
.months
;
220 mw
.language
.months
= {
222 names
: [ 'january', 'february', 'march', 'april', 'may_long', 'june',
223 'july', 'august', 'september', 'october', 'november', 'december' ],
224 genitive
: [ 'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen',
225 'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen', 'december-gen' ],
226 abbrev
: [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun',
227 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ]
229 names
: [ 'January', 'February', 'March', 'April', 'May', 'June',
230 'July', 'August', 'September', 'October', 'November', 'December' ],
231 genitive
: [ 'January', 'February', 'March', 'April', 'May', 'June',
232 'July', 'August', 'September', 'October', 'November', 'December' ],
233 abbrev
: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
234 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
237 teardown: function () {
238 mw
.language
.months
= this.liveMonths
;
241 wgDefaultDateFormat
: 'dmy',
242 wgSeparatorTransformTable
: [ '', '' ],
243 wgDigitTransformTable
: [ '', '' ],
244 wgPageContentLanguage
: 'en'
249 * Create an HTML table from an array of row arrays containing text strings.
250 * First row will be header row. No fancy rowspan/colspan stuff.
252 * @param {string[]} header
253 * @param {string[][]} data
256 function tableCreate( header
, data
) {
258 $table
= $( '<table class="sortable"><thead></thead><tbody></tbody></table>' ),
259 $thead
= $table
.find( 'thead' ),
260 $tbody
= $table
.find( 'tbody' ),
263 header
.forEach( function ( str
) {
264 var $th
= $( '<th>' );
265 $th
.text( str
).appendTo( $tr
);
267 $tr
.appendTo( $thead
);
269 for ( i
= 0; i
< data
.length
; i
++ ) {
271 // eslint-disable-next-line no-loop-func
272 data
[ i
].forEach( function ( str
) {
273 var $td
= $( '<td>' );
274 $td
.text( str
).appendTo( $tr
);
276 $tr
.appendTo( $tbody
);
282 * Extract text from table.
284 * @param {jQuery} $table
285 * @return {string[][]}
287 function tableExtract( $table
) {
290 $table
.find( 'tbody' ).find( 'tr' ).each( function ( i
, tr
) {
292 $( tr
).find( 'td,th' ).each( function ( i
, td
) {
293 row
.push( $( td
).text() );
301 * Run a table test by building a table with the given data,
302 * running some callback on it, then checking the results.
304 * @param {string} msg text to pass on to qunit for the comparison
305 * @param {string[]} header cols to make the table
306 * @param {string[][]} data rows/cols to make the table
307 * @param {string[][]} expected rows/cols to compare against at end
308 * @param {function($table)} callback something to do with the table before we compare
310 function tableTest( msg
, header
, data
, expected
, callback
) {
311 QUnit
.test( msg
, function ( assert
) {
313 $table
= tableCreate( header
, data
);
315 // Give caller a chance to set up sorting and manipulate the table.
318 // Table sorting is done synchronously; if it ever needs to change back
319 // to asynchronous, we'll need a timeout or a callback here.
320 extracted
= tableExtract( $table
);
321 assert
.deepEqual( extracted
, expected
, msg
);
326 * Run a table test by building a table with the given HTML,
327 * running some callback on it, then checking the results.
329 * @param {string} msg text to pass on to qunit for the comparison
330 * @param {string} html HTML to make the table
331 * @param {string[][]} expected Rows/cols to compare against at end
332 * @param {function($table)} callback Something to do with the table before we compare
334 function tableTestHTML( msg
, html
, expected
, callback
) {
335 QUnit
.test( msg
, function ( assert
) {
339 // Give caller a chance to set up sorting and manipulate the table.
343 $table
.tablesorter();
344 $table
.find( '#sortme' ).trigger( 'click' );
347 // Table sorting is done synchronously; if it ever needs to change back
348 // to asynchronous, we'll need a timeout or a callback here.
349 extracted
= tableExtract( $table
);
350 assert
.deepEqual( extracted
, expected
, msg
);
354 function reversed( arr
) {
356 var arr2
= arr
.slice( 0 );
363 // Sample data set using planets named and their radius
366 'Basic planet table: sorting initially - ascending by name',
370 function ( $table
) {
371 $table
.tablesorter( { sortList
: [
377 'Basic planet table: sorting initially - descending by radius',
380 reversed( planetsAscRadius
),
381 function ( $table
) {
382 $table
.tablesorter( { sortList
: [
388 'Basic planet table: ascending by name',
392 function ( $table
) {
393 $table
.tablesorter();
394 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
398 'Basic planet table: ascending by name a second time',
402 function ( $table
) {
403 $table
.tablesorter();
404 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
408 'Basic planet table: ascending by name (multiple clicks)',
412 function ( $table
) {
413 $table
.tablesorter();
414 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
415 $table
.find( '.headerSort:eq(1)' ).trigger( 'click' );
416 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
420 'Basic planet table: descending by name',
423 reversed( planetsAscName
),
424 function ( $table
) {
425 $table
.tablesorter();
426 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' ).trigger( 'click' );
430 'Basic planet table: ascending radius',
434 function ( $table
) {
435 $table
.tablesorter();
436 $table
.find( '.headerSort:eq(1)' ).trigger( 'click' );
440 'Basic planet table: descending radius',
443 reversed( planetsAscRadius
),
444 function ( $table
) {
445 $table
.tablesorter();
446 $table
.find( '.headerSort:eq(1)' ).trigger( 'click' ).trigger( 'click' );
450 'Sorting multiple columns by passing sort list',
454 function ( $table
) {
464 'Sorting multiple columns by programmatically triggering sort()',
468 function ( $table
) {
469 $table
.tablesorter();
470 $table
.data( 'tablesorter' ).sort(
479 'Reset to initial sorting by triggering sort() without any parameters',
483 function ( $table
) {
490 $table
.data( 'tablesorter' ).sort(
496 $table
.data( 'tablesorter' ).sort();
500 'Sort via click event after having initialized the tablesorter with initial sorting',
504 function ( $table
) {
506 { sortList
: [ { 0: 'asc' }, { 1: 'asc' } ] }
508 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
512 'Multi-sort via click event after having initialized the tablesorter with initial sorting',
516 function ( $table
) {
519 { sortList
: [ { 0: 'desc' }, { 1: 'desc' } ] }
521 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
523 // Pretend to click while pressing the multi-sort key
524 event
= $.Event( 'click' );
525 event
[ $table
.data( 'tablesorter' ).config
.sortMultiSortKey
] = true;
526 $table
.find( '.headerSort:eq(1)' ).trigger( event
);
529 QUnit
.test( 'Reset sorting making table appear unsorted', function ( assert
) {
530 var $table
= tableCreate( header
, simple
);
537 $table
.data( 'tablesorter' ).sort( [] );
540 $table
.find( 'th.headerSortUp' ).length
+ $table
.find( 'th.headerSortDown' ).length
,
542 'No sort specific sort classes addign to header cells'
546 $table
.find( 'th' ).first().attr( 'title' ),
547 mw
.msg( 'sort-ascending' ),
548 'First header cell has default title'
552 $table
.find( 'th' ).first().attr( 'title' ),
553 $table
.find( 'th' ).last().attr( 'title' ),
554 'Both header cells\' titles match'
558 // Sorting with colspans
560 tableTest( 'Sorting with colspanned headers: spanned column',
563 [ aaa1
, aab5
, abc3
, bbc2
, caa4
],
564 function ( $table
) {
565 // Make colspanned header for test
566 $table
.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
567 $table
.find( 'tr:eq(0) th:eq(0)' ).attr( 'colspan', '3' );
569 $table
.tablesorter();
570 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
573 tableTest( 'Sorting with colspanned headers: sort spanned column twice',
576 [ caa4
, bbc2
, abc3
, aab5
, aaa1
],
577 function ( $table
) {
578 // Make colspanned header for test
579 $table
.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
580 $table
.find( 'tr:eq(0) th:eq(0)' ).attr( 'colspan', '3' );
582 $table
.tablesorter();
583 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
584 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
587 tableTest( 'Sorting with colspanned headers: subsequent column',
590 [ aaa1
, bbc2
, abc3
, caa4
, aab5
],
591 function ( $table
) {
592 // Make colspanned header for test
593 $table
.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
594 $table
.find( 'tr:eq(0) th:eq(0)' ).attr( 'colspan', '3' );
596 $table
.tablesorter();
597 $table
.find( '.headerSort:eq(1)' ).trigger( 'click' );
600 tableTest( 'Sorting with colspanned headers: sort subsequent column twice',
603 [ aab5
, caa4
, abc3
, bbc2
, aaa1
],
604 function ( $table
) {
605 // Make colspanned header for test
606 $table
.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
607 $table
.find( 'tr:eq(0) th:eq(0)' ).attr( 'colspan', '3' );
609 $table
.tablesorter();
610 $table
.find( '.headerSort:eq(1)' ).trigger( 'click' );
611 $table
.find( '.headerSort:eq(1)' ).trigger( 'click' );
615 QUnit
.test( 'Basic planet table: one unsortable column', function ( assert
) {
616 var $table
= tableCreate( header
, planets
),
618 $table
.find( 'tr:eq(0) > th:eq(0)' ).addClass( 'unsortable' );
620 $table
.tablesorter();
621 $table
.find( 'tr:eq(0) > th:eq(0)' ).trigger( 'click' );
624 tableExtract( $table
),
629 $cell
= $table
.find( 'tr:eq(0) > th:eq(0)' );
630 $table
.find( 'tr:eq(0) > th:eq(1)' ).trigger( 'click' );
633 $cell
.hasClass( 'headerSortUp' ) || $cell
.hasClass( 'headerSortDown' ),
635 'after sort: no class headerSortUp or headerSortDown'
639 $cell
.attr( 'title' ),
641 'after sort: no title tag added'
648 'T30775: German-style (dmy) short numeric dates',
651 // German-style dates are day-month-year
659 // Sorted by ascending date
666 function ( $table
) {
667 mw
.config
.set( 'wgDefaultDateFormat', 'dmy' );
668 mw
.config
.set( 'wgPageContentLanguage', 'de' );
670 $table
.tablesorter();
671 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
676 'T30775: American-style (mdy) short numeric dates',
679 // American-style dates are month-day-year
687 // Sorted by ascending date
694 function ( $table
) {
695 mw
.config
.set( 'wgDefaultDateFormat', 'mdy' );
697 $table
.tablesorter();
698 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
703 'T19141: IPv4 address sorting',
707 function ( $table
) {
708 $table
.tablesorter();
709 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
713 'T19141: IPv4 address sorting (reverse)',
716 reversed( ipv4Sorted
),
717 function ( $table
) {
718 $table
.tablesorter();
719 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' ).trigger( 'click' );
724 'Accented Characters with custom collation',
728 function ( $table
) {
729 mw
.config
.set( 'tableSorterCollation', {
736 $table
.tablesorter();
737 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
742 'Accented Characters Swedish locale',
746 function ( $table
) {
747 mw
.config
.set( 'wgPageContentLanguage', 'sv' );
749 $table
.tablesorter();
750 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
755 'Digraphs with custom collation',
759 function ( $table
) {
760 mw
.config
.set( 'tableSorterCollation', {
765 $table
.tablesorter();
766 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
770 QUnit
.test( 'Rowspan not exploded on init', function ( assert
) {
771 var $table
= tableCreate( header
, planets
);
773 // Modify the table to have a multiple-row-spanning cell:
774 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
775 $table
.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
776 // - Set rowspan for 2nd cell of 3rd row to 3.
777 // This covers the removed cell in the 4th and 5th row.
778 $table
.find( 'tr:eq(2) td:eq(1)' ).attr( 'rowspan', '3' );
780 $table
.tablesorter();
783 $table
.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowSpan' ),
785 'Rowspan not exploded'
790 [ 'Earth', '6051.8' ],
792 [ 'Mars', '6051.8' ],
797 planetsRowspanII
= [ jupiter
, mercury
, saturn
, venus
, [ 'Venus', '6371.0' ], [ 'Venus', '3390.0' ] ];
800 'Basic planet table: same value for multiple rows via rowspan',
804 function ( $table
) {
805 // Modify the table to have a multiple-row-spanning cell:
806 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
807 $table
.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
808 // - Set rowspan for 2nd cell of 3rd row to 3.
809 // This covers the removed cell in the 4th and 5th row.
810 $table
.find( 'tr:eq(2) td:eq(1)' ).attr( 'rowspan', '3' );
812 $table
.tablesorter();
813 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
817 'Basic planet table: same value for multiple rows via rowspan (sorting initially)',
821 function ( $table
) {
822 // Modify the table to have a multiple-row-spanning cell:
823 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
824 $table
.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
825 // - Set rowspan for 2nd cell of 3rd row to 3.
826 // This covers the removed cell in the 4th and 5th row.
827 $table
.find( 'tr:eq(2) td:eq(1)' ).attr( 'rowspan', '3' );
829 $table
.tablesorter( { sortList
: [
835 'Basic planet table: Same value for multiple rows via rowspan II',
839 function ( $table
) {
840 // Modify the table to have a multiple-row-spanning cell:
841 // - Remove 1st cell of 4th row, and, 1st cell or 5th row.
842 $table
.find( 'tr:eq(3) td:eq(0), tr:eq(4) td:eq(0)' ).remove();
843 // - Set rowspan for 1st cell of 3rd row to 3.
844 // This covers the removed cell in the 4th and 5th row.
845 $table
.find( 'tr:eq(2) td:eq(0)' ).attr( 'rowspan', '3' );
847 $table
.tablesorter();
848 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
853 'Complex date parsing I',
857 function ( $table
) {
858 mw
.config
.set( 'wgDefaultDateFormat', 'mdy' );
860 $table
.tablesorter();
861 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
866 'Currency parsing I',
870 function ( $table
) {
871 $table
.tablesorter();
872 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
876 planetsAscNameLegacy
= planetsAscName
.slice( 0 );
877 planetsAscNameLegacy
[ 4 ] = planetsAscNameLegacy
[ 5 ];
878 planetsAscNameLegacy
.pop();
881 'Legacy compat with .sortbottom',
884 planetsAscNameLegacy
,
885 function ( $table
) {
886 $table
.find( 'tr:last' ).addClass( 'sortbottom' );
887 $table
.tablesorter();
888 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
892 QUnit
.test( 'Test detection routine', function ( assert
) {
895 '<table class="sortable">' +
896 '<caption>CAPTION</caption>' +
897 '<tr><th>THEAD</th></tr>' +
898 '<tr><td>1</td></tr>' +
899 '<tr class="sortbottom"><td>text</td></tr>' +
902 $table
.tablesorter();
903 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
906 $table
.data( 'tablesorter' ).config
.parsers
[ 0 ].id
,
908 'Correctly detected column content skipping sortbottom'
912 /** FIXME: the diff output is not very readeable. */
913 QUnit
.test( 'T34047 - caption must be before thead', function ( assert
) {
916 '<table class="sortable">' +
917 '<caption>CAPTION</caption>' +
918 '<tr><th>THEAD</th></tr>' +
919 '<tr><td>A</td></tr>' +
920 '<tr><td>B</td></tr>' +
921 '<tr class="sortbottom"><td>TFOOT</td></tr>' +
924 $table
.tablesorter();
927 $table
.children().get( 0 ).nodeName
,
929 'First element after <thead> must be <caption> (T34047)'
933 QUnit
.test( 'data-sort-value attribute, when available, should override sorting position', function ( assert
) {
936 // Example 1: All cells except one cell without data-sort-value,
937 // which should be sorted at it's text content value.
939 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
941 '<tr><td>Cheetah</td></tr>' +
942 '<tr><td data-sort-value="Apple">Bird</td></tr>' +
943 '<tr><td data-sort-value="Bananna">Ferret</td></tr>' +
944 '<tr><td data-sort-value="Drupe">Elephant</td></tr>' +
945 '<tr><td data-sort-value="Cherry">Dolphin</td></tr>' +
948 $table
.tablesorter().find( '.headerSort:eq(0)' ).trigger( 'click' );
951 $table
.find( 'tbody > tr' ).each( function ( i
, tr
) {
952 $( tr
).find( 'td' ).each( function ( i
, td
) {
954 data
: $( td
).data( 'sortValue' ),
960 assert
.deepEqual( data
, [
981 ], 'Order matches expected order (based on data-sort-value attribute values)' );
985 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
987 '<tr><td>D</td></tr>' +
988 '<tr><td data-sort-value="E">A</td></tr>' +
989 '<tr><td>B</td></tr>' +
990 '<tr><td>G</td></tr>' +
991 '<tr><td data-sort-value="F">C</td></tr>' +
992 '<tr><td><span data-sort-value="D">H</span></td></tr>' +
995 $table
.tablesorter().find( '.headerSort:eq(0)' ).trigger( 'click' );
998 $table
.find( 'tbody > tr' ).each( function ( i
, tr
) {
999 $( tr
).find( 'td' ).each( function ( i
, td
) {
1001 data
: $( td
).data( 'sortValue' ),
1002 text
: $( td
).text()
1007 assert
.deepEqual( data
, [
1032 ], 'Order matches expected order (based on data-sort-value attribute values)' );
1034 // Example 3: Test that live changes are used from data-sort-value,
1035 // even if they change after the tablesorter is constructed (T40152).
1037 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
1039 '<tr><td>D</td></tr>' +
1040 '<tr><td data-sort-value="1">A</td></tr>' +
1041 '<tr><td>B</td></tr>' +
1042 '<tr><td data-sort-value="2">G</td></tr>' +
1043 '<tr><td>C</td></tr>' +
1046 // initialize table sorter and sort once
1049 .find( '.headerSort:eq(0)' ).trigger( 'click' );
1051 // Change the sortValue data properties (T40152)
1053 $table
.find( 'td:contains(A)' ).data( 'sortValue', 3 );
1055 $table
.find( 'td:contains(B)' ).data( 'sortValue', 1 );
1056 // - remove data, bring back attribute: 2
1057 $table
.find( 'td:contains(G)' ).removeData( 'sortValue' );
1059 // Now sort again (twice, so it is back at Ascending)
1060 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1061 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1064 $table
.find( 'tbody > tr' ).each( function ( i
, tr
) {
1065 $( tr
).find( 'td' ).each( function ( i
, td
) {
1067 data
: $( td
).data( 'sortValue' ),
1068 text
: $( td
).text()
1073 assert
.deepEqual( data
, [
1094 ], 'Order matches expected order, using the current sortValue in $.data()' );
1098 tableTest( 'T10115: sort numbers with commas (ascending)',
1099 [ 'Numbers' ], numbers
, numbersAsc
,
1100 function ( $table
) {
1101 $table
.tablesorter();
1102 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1106 tableTest( 'T10115: sort numbers with commas (descending)',
1107 [ 'Numbers' ], numbers
, reversed( numbersAsc
),
1108 function ( $table
) {
1109 $table
.tablesorter();
1110 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' ).trigger( 'click' );
1113 // TODO add numbers sorting tests for T10115 with a different language
1115 QUnit
.test( 'T34888 - Tables inside a tableheader cell', function ( assert
) {
1118 '<table class="sortable" id="mw-bug-32888">' +
1119 '<tr><th>header<table id="mw-bug-32888-2">' +
1120 '<tr><th>1</th><th>2</th></tr>' +
1121 '</table></th></tr>' +
1122 '<tr><td>A</td></tr>' +
1123 '<tr><td>B</td></tr>' +
1126 $table
.tablesorter();
1129 $table
.find( '> thead:eq(0) > tr > th.headerSort' ).length
,
1131 'Child tables inside a headercell should not interfere with sortable headers (T34888)'
1134 $( '#mw-bug-32888-2' ).find( 'th.headerSort' ).length
,
1136 'The headers of child tables inside a headercell should not be sortable themselves (T34888)'
1141 'Correct date sorting I',
1143 correctDateSorting1
,
1144 correctDateSortingSorted1
,
1145 function ( $table
) {
1146 mw
.config
.set( 'wgDefaultDateFormat', 'mdy' );
1148 $table
.tablesorter();
1149 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1154 'Correct date sorting II',
1156 correctDateSorting2
,
1157 correctDateSortingSorted2
,
1158 function ( $table
) {
1159 mw
.config
.set( 'wgDefaultDateFormat', 'dmy' );
1161 $table
.tablesorter();
1162 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1170 isoDateSortingSorted
,
1171 function ( $table
) {
1172 mw
.config
.set( 'wgDefaultDateFormat', 'dmy' );
1174 $table
.tablesorter();
1175 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1179 QUnit
.test( 'Sorting images using alt text', function ( assert
) {
1181 '<table class="sortable">' +
1182 '<tr><th>THEAD</th></tr>' +
1183 '<tr><td><img alt="2"/></td></tr>' +
1184 '<tr><td>1</td></tr>' +
1187 $table
.tablesorter().find( '.headerSort:eq(0)' ).trigger( 'click' );
1190 $table
.find( 'td' ).first().text(),
1192 'Applied correct sorting order'
1196 QUnit
.test( 'Sorting images using alt text (complex)', function ( assert
) {
1198 '<table class="sortable">' +
1199 '<tr><th>THEAD</th></tr>' +
1200 '<tr><td><img alt="D" />A</td></tr>' +
1201 '<tr><td>CC</td></tr>' +
1202 '<tr><td><a><img alt="A" /></a>F</tr>' +
1203 '<tr><td><img alt="A" /><strong>E</strong></tr>' +
1204 '<tr><td><strong><img alt="A" />D</strong></tr>' +
1205 '<tr><td><img alt="A" />C</tr>' +
1208 $table
.tablesorter().find( '.headerSort:eq(0)' ).trigger( 'click' );
1211 $table
.find( 'td' ).text(),
1213 'Applied correct sorting order'
1217 QUnit
.test( 'Sorting images using alt text (with format autodetection)', function ( assert
) {
1219 '<table class="sortable">' +
1220 '<tr><th>THEAD</th></tr>' +
1221 '<tr><td><img alt="1" />7</td></tr>' +
1222 '<tr><td>1<img alt="6" /></td></tr>' +
1223 '<tr><td>5</td></tr>' +
1224 '<tr><td>4</td></tr>' +
1227 $table
.tablesorter().find( '.headerSort:eq(0)' ).trigger( 'click' );
1230 $table
.find( 'td' ).text(),
1232 'Applied correct sorting order'
1236 QUnit
.test( 'T40911 - The row with the largest amount of columns should receive the sort indicators', function ( assert
) {
1238 '<table class="sortable">' +
1240 '<tr><th rowspan="2" id="A1">A1</th><th colspan="2">B2a</th></tr>' +
1241 '<tr><th id="B2b">B2b</th><th id="C2b">C2b</th></tr>' +
1243 '<tr><td>A</td><td>Aa</td><td>Ab</td></tr>' +
1244 '<tr><td>B</td><td>Ba</td><td>Bb</td></tr>' +
1247 $table
.tablesorter();
1250 $table
.find( '#A1' ).attr( 'class' ),
1252 'The first column of the first row should be sortable'
1255 $table
.find( '#B2b' ).attr( 'class' ),
1257 'The th element of the 2nd row of the 2nd column should be sortable'
1260 $table
.find( '#C2b' ).attr( 'class' ),
1262 'The th element of the 2nd row of the 3rd column should be sortable'
1266 QUnit
.test( 'rowspans in table headers should prefer the last row when rows are equal in length', function ( assert
) {
1268 '<table class="sortable">' +
1270 '<tr><th rowspan="2" id="A1">A1</th><th>B2a</th></tr>' +
1271 '<tr><th id="B2b">B2b</th></tr>' +
1273 '<tr><td>A</td><td>Aa</td></tr>' +
1274 '<tr><td>B</td><td>Ba</td></tr>' +
1277 $table
.tablesorter();
1280 $table
.find( '#A1' ).attr( 'class' ),
1282 'The first column of the first row should be sortable'
1285 $table
.find( '#B2b' ).attr( 'class' ),
1287 'The th element of the 2nd row of the 2nd column should be sortable'
1291 QUnit
.test( 'holes in the table headers should not throw JS errors', function ( assert
) {
1293 '<table class="sortable">' +
1295 '<tr><th id="A1">A1</th><th>B1</th><th id="C1" rowspan="2">C1</th></tr>' +
1296 '<tr><th id="A2">A2</th></tr>' +
1298 '<tr><td>A</td><td>Aa</td><td>Aaa</td></tr>' +
1299 '<tr><td>B</td><td>Ba</td><td>Bbb</td></tr>' +
1302 $table
.tablesorter();
1303 assert
.strictEqual( $table
.find( '#A2' ).data( 'headerIndex' ),
1305 'A2 should not be a sort header'
1307 assert
.strictEqual( $table
.find( '#C1' ).data( 'headerIndex' ),
1309 'C1 should be a sort header'
1314 QUnit
.test( 'td cells in thead should not be taken into account for longest row calculation', function ( assert
) {
1316 '<table class="sortable">' +
1318 '<tr><th id="A1">A1</th><th>B1</th><td id="C1">C1</td></tr>' +
1319 '<tr><th id="A2">A2</th><th>B2</th><th id="C2">C2</th></tr>' +
1323 $table
.tablesorter();
1324 assert
.strictEqual( $table
.find( '#C2' ).data( 'headerIndex' ),
1326 'C2 should be a sort header'
1328 assert
.strictEqual( $table
.find( '#C1' ).data( 'headerIndex' ),
1330 'C1 should not be a sort header'
1334 // T43889 - exploding rowspans in more complex cases
1336 'Rowspan exploding with row headers',
1337 '<table class="sortable">' +
1338 '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' +
1340 '<tr><td>1</td><th rowspan="2">foo</th><td rowspan="2">bar</td><td>baz</td></tr>' +
1341 '<tr><td>2</td><td>baz</td></tr>' +
1344 [ '1', 'foo', 'bar', 'baz' ],
1345 [ '2', 'foo', 'bar', 'baz' ]
1349 // T55211 - exploding rowspans in more complex cases
1351 'Rowspan exploding with row headers and colspans', function ( assert
) {
1352 var $table
= $( '<table class="sortable">' +
1353 '<thead><tr><th rowspan="2">n</th><th colspan="2">foo</th><th rowspan="2">baz</th></tr>' +
1354 '<tr><th>foo</th><th>bar</th></tr></thead>' +
1356 '<tr><td>1</td><td>foo</td><td>bar</td><td>baz</td></tr>' +
1357 '<tr><td>2</td><td>foo</td><td>bar</td><td>baz</td></tr>' +
1358 '</tbody></table>' );
1360 $table
.tablesorter();
1361 assert
.strictEqual( $table
.find( 'tr:eq(1) th:eq(1)' ).data( 'headerIndex' ),
1363 'Incorrect index of sort header'
1369 'Rowspan exploding with colspanned cells',
1370 '<table class="sortable">' +
1371 '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' +
1373 '<tr><td>1</td><td>foo</td><td>bar</td><td rowspan="2">baz</td></tr>' +
1374 '<tr><td>2</td><td colspan="2">foobar</td></tr>' +
1377 [ '1', 'foo', 'bar', 'baz' ],
1378 [ '2', 'foobar', 'baz' ]
1383 'Rowspan exploding with colspanned cells (2)',
1384 '<table class="sortable">' +
1385 '<thead><tr><th>n</th><th>foo</th><th>bar</th><th>baz</th><th id="sortme">n2</th></tr></thead>' +
1387 '<tr><td>1</td><td>foo</td><td>bar</td><td rowspan="2">baz</td><td>2</td></tr>' +
1388 '<tr><td>2</td><td colspan="2">foobar</td><td>1</td></tr>' +
1391 [ '2', 'foobar', 'baz', '1' ],
1392 [ '1', 'foo', 'bar', 'baz', '2' ]
1397 'Rowspan exploding with rightmost rows spanning most',
1398 '<table class="sortable">' +
1399 '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th></tr></thead>' +
1401 '<tr><td>1</td><td rowspan="2">foo</td><td rowspan="4">bar</td></tr>' +
1402 '<tr><td>2</td></tr>' +
1403 '<tr><td>3</td><td rowspan="2">foo</td></tr>' +
1404 '<tr><td>4</td></tr>' +
1407 [ '1', 'foo', 'bar' ],
1408 [ '2', 'foo', 'bar' ],
1409 [ '3', 'foo', 'bar' ],
1410 [ '4', 'foo', 'bar' ]
1415 'Rowspan exploding with rightmost rows spanning most (2)',
1416 '<table class="sortable">' +
1417 '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' +
1419 '<tr><td>1</td><td rowspan="2">foo</td><td rowspan="4">bar</td><td>baz</td></tr>' +
1420 '<tr><td>2</td><td>baz</td></tr>' +
1421 '<tr><td>3</td><td rowspan="2">foo</td><td>baz</td></tr>' +
1422 '<tr><td>4</td><td>baz</td></tr>' +
1425 [ '1', 'foo', 'bar', 'baz' ],
1426 [ '2', 'foo', 'bar', 'baz' ],
1427 [ '3', 'foo', 'bar', 'baz' ],
1428 [ '4', 'foo', 'bar', 'baz' ]
1433 'Rowspan exploding with row-and-colspanned cells',
1434 '<table class="sortable">' +
1435 '<thead><tr><th id="sortme">n</th><th>foo1</th><th>foo2</th><th>bar</th><th>baz</th></tr></thead>' +
1437 '<tr><td>1</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="4">bar</td><td>baz</td></tr>' +
1438 '<tr><td>2</td><td>baz</td></tr>' +
1439 '<tr><td>3</td><td colspan="2" rowspan="2">foo</td><td>baz</td></tr>' +
1440 '<tr><td>4</td><td>baz</td></tr>' +
1443 [ '1', 'foo1', 'foo2', 'bar', 'baz' ],
1444 [ '2', 'foo1', 'foo2', 'bar', 'baz' ],
1445 [ '3', 'foo', 'bar', 'baz' ],
1446 [ '4', 'foo', 'bar', 'baz' ]
1451 'Rowspan exploding with uneven rowspan layout',
1452 '<table class="sortable">' +
1453 '<thead><tr><th id="sortme">n</th><th>foo1</th><th>foo2</th><th>foo3</th><th>bar</th><th>baz</th></tr></thead>' +
1455 '<tr><td>1</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="2">foo3</td><td>bar</td><td>baz</td></tr>' +
1456 '<tr><td>2</td><td rowspan="3">bar</td><td>baz</td></tr>' +
1457 '<tr><td>3</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="2">foo3</td><td>baz</td></tr>' +
1458 '<tr><td>4</td><td>baz</td></tr>' +
1461 [ '1', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ],
1462 [ '2', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ],
1463 [ '3', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ],
1464 [ '4', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ]
1468 QUnit
.test( 'T105731 - incomplete rows in table body', function ( assert
) {
1469 var $table
, parsers
;
1471 '<table class="sortable">' +
1472 '<tr><th>A</th><th>B</th></tr>' +
1473 '<tr><td>3</td></tr>' +
1474 '<tr><td>1</td><td>2</td></tr>' +
1477 $table
.tablesorter();
1478 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1479 // now the first row have 2 columns
1480 $table
.find( '.headerSort:eq(1)' ).trigger( 'click' );
1482 parsers
= $table
.data( 'tablesorter' ).config
.parsers
;
1487 'detectParserForColumn() detect 2 parsers'
1493 'detectParserForColumn() detect parser.id "number" for second column'
1497 parsers
[ 1 ].format( $table
.find( 'tbody > tr > td:eq(1)' ).text() ),
1499 'empty cell is sorted as number -Infinity'
1503 QUnit
.test( 'bug T114721 - use of expand-child class', function ( assert
) {
1504 var $table
, parsers
;
1506 '<table class="sortable">' +
1507 '<tr><th>A</th><th>B</th></tr>' +
1508 '<tr><td>b</td><td>4</td></tr>' +
1509 '<tr class="expand-child"><td colspan="2">some text follow b</td></tr>' +
1510 '<tr><td>a</td><td>2</td></tr>' +
1511 '<tr class="expand-child"><td colspan="2">some text follow a</td></tr>' +
1512 '<tr class="expand-child"><td colspan="2">more text</td></tr>' +
1515 $table
.tablesorter();
1516 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1519 tableExtract( $table
),
1522 [ 'some text follow a' ],
1525 [ 'some text follow b' ]
1527 'row with expand-child class follow above row'
1530 parsers
= $table
.data( 'tablesorter' ).config
.parsers
;
1534 'detectParserForColumn() detect parser.id "number" for second column'
1537 QUnit
.test( 'T29745 - References ignored in sortkey', function ( assert
) {
1538 var $table
, parsers
;
1540 '<table class="sortable">' +
1541 '<tr><th>A</th></tr>' +
1542 '<tr><td>10</td></tr>' +
1543 '<tr><td>2<sup class="reference"><a href="#cite_note-1">[1]</a></sup></td></tr>' +
1546 $table
.tablesorter();
1547 $table
.find( '.headerSort:eq(0)' ).trigger( 'click' );
1550 tableExtract( $table
),
1555 'References ignored in sortkey'
1558 parsers
= $table
.data( 'tablesorter' ).config
.parsers
;
1562 'detectParserForColumn() detect parser.id "number"'