mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-12-05 05:04:20 +00:00
Core: duplicateSpan false now uses textExtraction
See http://stackoverflow.com/q/36449711/145346
This commit is contained in:
parent
2eb0a1dd1b
commit
053553d4dd
@ -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;
|
||||
|
@ -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('<table class="tablesorter">' +
|
||||
'<thead><tr><th>1</th><th>2</th><th>3</th><th>4</th></tr></thead>' +
|
||||
'<tbody>' +
|
||||
'<tr><td>1</td><td colspan="2">2</td><td>3</td></tr>' +
|
||||
'<tr><td colspan="3"><span class="col0">y0</span><span class="col1">y1</span><span class="col2">y2</span></td><td>z</td></tr>' +
|
||||
'<tr><td>a</td><td>b</td><td colspan="2"><span class="col2">c1</span><span class="col3">c2</span></td></tr>' +
|
||||
'</tbody></table>')
|
||||
.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) {
|
||||
|
Loading…
Reference in New Issue
Block a user