From 053553d4dd4e21e6d764ba463d72e62fd6bdcadb Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Wed, 6 Apr 2016 22:15:38 -0500 Subject: [PATCH] Core: duplicateSpan false now uses textExtraction See http://stackoverflow.com/q/36449711/145346 --- js/jquery.tablesorter.js | 11 +++++++++-- testing/testing.js | 31 ++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index 134978f9..c72ab4d1 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -941,8 +941,15 @@ index = 0; while ( index <= span ) { // duplicate text (or not) to spanned columns - rowData.raw[ cacheIndex + index ] = c.duplicateSpan || index === 0 ? val : ''; - cols[ cacheIndex + index ] = c.duplicateSpan || index === 0 ? val : ''; + // instead of setting duplicate span to empty string, use textExtraction to try to get a value + // see http://stackoverflow.com/q/36449711/145346 + txt = c.duplicateSpan || index === 0 ? + val : + typeof c.textExtraction !== 'string' ? + ts.getElementText( c, cell, cacheIndex + index ) || '' : + ''; + rowData.raw[ cacheIndex + index ] = txt; + cols[ cacheIndex + index ] = txt; index++; } cacheIndex += span; diff --git a/testing/testing.js b/testing/testing.js index f14a3cd1..ff434432 100644 --- a/testing/testing.js +++ b/testing/testing.js @@ -614,7 +614,7 @@ jQuery(function($){ }); QUnit.test( 'colspan parsing', function(assert) { - assert.expect(2); + assert.expect(3); t = [ 'g1', '6', 'a9', 155, 'l', 'nytimes', @@ -646,6 +646,35 @@ jQuery(function($){ ]; assert.cacheCompare( $('#testblock table')[0], 'all', t, 'colspans not duplicated in cache (duplicateSpan:false)' ); + // See http://stackoverflow.com/q/36449711/145346 + $('#testblock').html('' + + '' + + '' + + '' + + '' + + '' + + '
1234
123
y0y1y2z
abc1c2
') + .find('table') + .tablesorter({ + headers : { '*' : { sorter: 'text' } }, + textExtraction: function(node, table, cellIndex) { + var $span = $(node).find('.col' + cellIndex); + if ($span.length) { + return $span.text(); + } + return node.textContent; + }, + duplicateSpan: false + }); + t = [ + '1', '2', '2', '3', + 'y0', 'y1', 'y2', 'z', + 'a', 'b', 'c1', 'c2' + ]; + assert.cacheCompare( $('#testblock table')[0], 'all', t, 'colspans not duplicated but textExtraction defined' ); + + + }); QUnit.test( 'sorton methods', function(assert) {