Skip to content

Commit

Permalink
jmosbech#58: performance fix: cache header cells when updating width.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmosbech committed Apr 5, 2014
1 parent 57777f0 commit 340d699
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions js/jquery.stickytableheaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,21 @@
return;
}
// Copy cell widths from clone
var $origHeaders = $('th,td', base.$originalHeader);
var $clonedHeaders = $('th,td', base.$clonedHeader);
base.cellWidths = [];
base.getWidth($clonedHeaders);
base.setWidth($clonedHeaders, $origHeaders);
if (!base.$originalHeaderCells) {
base.$originalHeaderCells = $('th,td', base.$originalHeader);
}
if (!base.$clonedHeaderCells) {
base.$clonedHeaderCells = $('th,td', base.$clonedHeader);
}
var cellWidths = base.getWidth(base.$clonedHeaderCells);
base.setWidth(cellWidths, base.$clonedHeaderCells, base.$originalHeaderCells);

// Copy row width from whole table
base.$originalHeader.css('width', base.$clonedHeader.width());
};

base.getWidth = function ($clonedHeaders) {
var widths = [];
$clonedHeaders.each(function (index) {
var width, $this = $(this);

Expand All @@ -202,13 +206,14 @@
width = $this.width();
}

base.cellWidths[index] = width;
widths[index] = width;
});
return widths;
};

base.setWidth = function ($clonedHeaders, $origHeaders) {
base.setWidth = function (widths, $clonedHeaders, $origHeaders) {
$clonedHeaders.each(function (index) {
var width = base.cellWidths[index];
var width = widths[index];
$origHeaders.eq(index).css({
'min-width': width,
'max-width': width
Expand Down

0 comments on commit 340d699

Please sign in to comment.