Skip to content

Instantly share code, notes, and snippets.

@reachkamrul
Last active April 24, 2020 11:02
Show Gist options
  • Save reachkamrul/52902cbeeffb342de98f1da9ce51b567 to your computer and use it in GitHub Desktop.
Save reachkamrul/52902cbeeffb342de98f1da9ce51b567 to your computer and use it in GitHub Desktop.
Auto Colspan for same cell data
jQuery(document).ready(function() {
function ninjaTableAutoColspan()
{
if($table.hasClass('ninja_stacked_table')) {
return;
}
$table.find('tr').each(function() {
var tr = this;
var counter = 0;
var strLookupText = '';
var isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);
jQuery('td', tr).each(function(index, value) {
var td = jQuery(this);
if(!isHTML(td[0].innerHTML) && td[0].innerHTML !== ''){
if ((td.text() === strLookupText) ) {
counter++;
td.prev().attr('colspan', '' + parseInt(counter + 1,10) + '').css({textAlign : 'center'});
td.remove();
}
}
else {
counter = 0;
}
strLookupText = td.text();
});
});
}
ninjaTableAutoColspan();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment