Fix a bug in fixStickyHeader, allow to use `width` style on fixed cells

rel-1.0
Vitaliy Filippov 2016-08-18 17:06:33 +03:00
parent 2ba24b71eb
commit c465fb4ed3
1 changed files with 23 additions and 18 deletions

View File

@ -1,7 +1,7 @@
// Simple Sticky Header and Column implementation for HTML tables // Simple Sticky Header and Column implementation for HTML tables
// (c) Vitaliy Filippov 2016 // (c) Vitaliy Filippov 2016
// License: MPL 2.0+ // License: MPL 2.0+
// Version: 2016-08-15 // Version: 2016-08-18
// USAGE: // USAGE:
// makeStickyHeaders(table): add sticky header and footer to table // makeStickyHeaders(table): add sticky header and footer to table
@ -79,13 +79,14 @@ window.makeStickyHeaders = function(table)
for (var i = 0; i < rs[0].children.length; i++) for (var i = 0; i < rs[0].children.length; i++)
{ {
var e = rs[0].children[i]; var e = rs[0].children[i];
e._oldWidth = e.style.width;
e._sticky = true;
e.style.position = 'absolute'; e.style.position = 'absolute';
e.style.width = w[i]+'px'; e.style.width = w[i]+'px';
e.style.height = h+'px'; e.style.height = h+'px';
e.style.left = l[i]+'px'; e.style.left = l[i]+'px';
e.style.display = 'block'; e.style.display = 'block';
e.style.zIndex = '1'; e.style.zIndex = '1';
e._sticky = true;
} }
// Try to minimise reflows: (1) make some changes // Try to minimise reflows: (1) make some changes
for (var i = rs.length-1; i >= 0; i--) for (var i = rs.length-1; i >= 0; i--)
@ -97,7 +98,7 @@ window.makeStickyHeaders = function(table)
var e = rs[i].children[0]; var e = rs[i].children[0];
var d = e.cloneNode(true); var d = e.cloneNode(true);
d.style.visibility = 'hidden'; d.style.visibility = 'hidden';
e.parentNode.insertBefore(d, e.nextSibling); rs[i].insertBefore(d, e.nextSibling);
if (i != 0) if (i != 0)
{ {
e.style.position = 'absolute'; e.style.position = 'absolute';
@ -124,6 +125,7 @@ window.makeStickyHeaders = function(table)
if (!rs[i].children.length) if (!rs[i].children.length)
continue; continue;
var e = rs[i].children[0]; var e = rs[i].children[0];
e._oldWidth = e.style.width;
e.style.height = hs[i]+'px'; e.style.height = hs[i]+'px';
e.style.width = w[0]+'px'; e.style.width = w[0]+'px';
} }
@ -162,7 +164,7 @@ window.fixStickyRows = function(table, trs, nocols)
d = e.cloneNode(true); d = e.cloneNode(true);
d.className = d.className.replace(' _scri'+table._scri, ''); d.className = d.className.replace(' _scri'+table._scri, '');
d.style.visibility = 'hidden'; d.style.visibility = 'hidden';
d.style.width = ''; d.style.width = e._oldWidth;
d.style.height = ''; d.style.height = '';
d.style.position = ''; d.style.position = '';
d.style.display = ''; d.style.display = '';
@ -265,24 +267,27 @@ window.fixStickyHeader = function(table, nocols)
var sr = table._sizerow; var sr = table._sizerow;
while (sr.children[1]) while (sr.children[1])
sr.removeChild(sr.children[1]); sr.removeChild(sr.children[1]);
var e, renew = false; var b, e, renew = false;
for (var i = 0; i < tr.children.length; i++) for (var i = 0; i < tr.children.length; i++)
{ {
e = tr.children[i]; b = tr.children[i];
if (!e._sticky) e = b.cloneNode(true);
if (b._sticky)
{
if (i == 0)
e.className = e.className.replace(' _scri'+table._scri, '');
e.style.position = '';
e.style.width = b._oldWidth;
e.style.height = '';
e.style.left = '';
e.style.display = '';
e.style.zIndex = '';
if (i == 0)
i++;
}
else
renew = true; renew = true;
e = e.cloneNode(true);
if (i == 0)
e.className = e.className.replace(' _scri'+table._scri, '');
e.style.position = '';
e.style.width = '';
e.style.height = '';
e.style.left = '';
e.style.display = '';
e.style.zIndex = '';
sr.appendChild(e); sr.appendChild(e);
if (e._sticky && i == 0)
i++;
} }
if (renew) if (renew)
{ {