Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing row height when cloning the original table #21

Closed
wants to merge 8 commits into from
31 changes: 14 additions & 17 deletions responsive-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $(document).ready(function() {
original.wrap("<div class='scrollable' />");

setCellHeights(original, copy);
setTableHeights(original, copy);
}

function unsplitTable(original) {
Expand All @@ -43,25 +44,21 @@ $(document).ready(function() {
}

function setCellHeights(original, copy) {
var tr = original.find('tr'),
tr_copy = copy.find('tr'),
heights = [];

tr.each(function (index) {
var self = $(this),
tx = self.find('th, td');

tx.each(function () {
var height = $(this).outerHeight(true);
heights[index] = heights[index] || 0;
if (height > heights[index]) heights[index] = height;
});

$('tr', original).each(function(index){
oheight = $(this).height();
cheight = $('tr:eq('+index+')', copy).height();
height = (oheight > cheight ? oheight : cheight);
$('th,td', original).css('height', height+'px');
$('th,td', copy).css('height', height+'px');
});
}

tr_copy.each(function (index) {
$(this).height(heights[index]);
});
function setTableHeights(original, copy) {
oheight = original.outerHeight();
cheight = copy.outerHeight();
height = (oheight > cheight ? oheight : cheight);
original.css('min-height', height+'px');
copy.css('min-height', height+'px');
}

});