From 23c94a726d6e3f4a92d754630abfa9256654dbb8 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Wed, 7 Jun 2017 22:38:57 -0500 Subject: [PATCH] Core: Show console error for mismatched column count. See #1415 --- js/jquery.tablesorter.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index a5b632ad..8a52fcc2 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -2275,9 +2275,42 @@ } } } + ts.checkColumnCount($rows, matrix, matrixrow.length); return matrixrow.length; }, + checkColumnCount : function($rows, matrix, columns) { + // this DOES NOT report any tbody column issues, except for the math and + // and column selector widgets + var i, len, + valid = true, + cells = []; + for ( i = 0; i < matrix.length; i++ ) { + // some matrix entries are undefined when testing the footer because + // it is using the rowIndex property + if ( matrix[i] ) { + len = matrix[i].length; + if ( matrix[i].length !== columns ) { + valid = false; + break; + } + } + } + if ( !valid ) { + $rows.each( function( indx, el ) { + var cell = el.parentElement.nodeName; + if ( cells.indexOf( cell ) ) { + cells.push( cell ); + } + }); + console.error( + 'Invalid or incorrect number of columns in the ' + + cells.join( ' or ' ) + '; expected ' + columns + + ', but found ' + len + ' columns' + ); + } + }, + // automatically add a colgroup with col elements set to a percentage width fixColumnWidth : function( table ) { table = $( table )[ 0 ];