
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
sticky-html-table
Advanced tools
Tools to make large HTML table headers and sidebars to stick on the screen when scrolling.
Tools to make large HTML table headers and sidebars to stick on the screen when scrolling.
(or atleast what this package assumes and prepares for)
A table consists of
The table header can have multiple rows, and any kind of merged cells. Table headers (<thead>) only contains <th> elements.
The table sidebar can have multiple columns, and any kind of merged cells. The <th> cells which contained in a <tbody> element are considered to be sidebar cells.
A table section header is a single table row usually fully merged and stlyed like the table header.
Sections can be separated into their own <tbody> where the first row is the section header, or just left in one big <tbody> element.
Note: The
<tfoot>element has no role in this implementation, and may break the table if used. Note: The<colgroup>element can be used to style the table columns freely.
dist/sticky-table.css and dist/sticky-table.js.src/sticky-table.scss in Sass and src/sticky-table.ts in TS module.sticky class, or call StickyTables.init(options) to access advanced customization options.<table class="sticky">
<thead>
<tr><th>A</th><th>B</th><th>C</th></tr>
<tr><th>AA</th><th>BB</th><th>CC</th></tr>
</thead>
<tbody>
<tr class="sticky"><th colspan="3">Block 1</th></tr>
<tr><th>1</th><th>11</th><th>111</th></tr>
<tr><th>2</th><th>22</th><th>222</th></tr>
<tr><th>3</th><th>33</th><th>333</th></tr>
</tbody>
<tbody>
<tr class="sticky"><th colspan="3">Block 2</th></tr>
<tr><th>1</th><th>11</th><th>111</th></tr>
<tr><th>2</th><th>22</th><th>222</th></tr>
<tr><th>3</th><th>33</th><th>333</th></tr>
</tbody>
</table>
<script>
StickyTables.init();
</script>
For the CSS to work it is required to have aria-colindex and aria-rowindex attributes on every table cell.
This helps to properly reference each header row and each sidebar column targeted to be sticky.
The addTableCellAriaRowColIndexes(table) function is responsible to add these aria attributes to each cell when these are missing.
To position each row and column correctly, we use CSS properties that is applied by addStickyTableCssVariables(table) function to the table element. This defines each row height and each column width which allows us to have multi-row tall header and multi-column wide sidebar.
Our tables can have sections, usually in a form of the whole table row merged together.
This package currently provides support for sections only in vertical axis direction, with a limitation of equal height rows for the section headers.
Mark each row element with sticky class and the row will always stick below the table header while scrolling down.
Only a sticky class is defined, and does different things when present on different elements.
<table> element: Makes the table header and sidebar to be sticky.<tr> element: Makes the entire row stick to the table viewport.<span> in a table cell: Makes the contents of the cell stick to the table viewport. Eg. for merged cells spanning a lot of columns/rows containing some text that should be visible.Note: Sticky rows (section headers) can have sticky spans in them. The sticky span makes the content always aligned to screen center.
The following CSS variables used when we position the cells:
--stickytables-row-<i>-top: To offset table header rows from the top.--stickytables-column-<i>-left: To offset table sidebar columns from the left side.--stickytables-top: To offset anything below the last table header row.--stickytables-left: To offset anything next to the last table sidebar column.--viewport-width: Defines the table max visible area. Used when the table section header contains <span class="sticky"> elements.--padding-{top,right,bottom,left}: Cell padding. Used when table cells has <span class="sticky"> elements.These variables can be generated with the init() call automatically.
init(options: InitOptions = {}): voidThis call prepares the table to work with the suppiled css.
You can specify the following options
ariaRowColIndexesExisting?: boolean;
When aria-colindex and aria-rowindex does not exists, a we generate them programmatically.
Default: false
customSelector?: string;
CSS selector of the table element.
Default: table.sticky
stickySections?: boolean | string;
Boolean or a single class name that marks section headers table rows.
When true it targets rows with sticky class name.
Default: false
stickyWrapHeadContent?: boolean;
Header cell contents wrapped in a sticky box to stick to screen when cells are wide.
Default: false
stickyWrapSideContent?: boolean;
Sidebar cell contents wrapped in a sticky box to stick to screen when cells are tall
Default: false
stickyWrapSectionsContent?: boolean;
Section content wrapped in a sticky box, centered on screen.
Default: false
addViewportWidthVars?: boolean;
Set and manage --viewport-width CSS variable on DocumentElement, required by sticky-wrapped section cells.
Default: false
addPaddingVars?: boolean;
Set --padding-{top,right,bottom,left} CSS variables on the table element on load, required by sticky-wrapped cells.
Default: false
offsetTop?: number | { (): number };
Offset sticky table screen top position.
Default: 0
offsetLeft?: number | { (): number };
Offset sticky table screen left position.
Default: 0
addTableCellAriaRowColIndexes(table: HTMLTableElement): voidGenerates the aria-colindex and aria-rowindex attributes on table cells.
Called by init when ariaRowColIndexesExisting: true.
addStickyTableCssVariables(table: HTMLTableElement, offsetTop = 0, offsetLeft = 0): voidGenerates CSS vairables required to keep multiple rows and columns on screen.
Always called by init.
stickyWrapHeadContent(table: HTMLTableElement): voidWraps each header cells content into a sticky box that keeps the cell content on-screen as much as possible.
Called by init when stickyWrapHeadContent: true.
stickyWrapSideContent(table: HTMLTableElement): voidWraps each sidebar cells content into a sticky box that keeps the cell content on-screen as much as possible.
Called by init when stickyWrapSideContent: true.
stickyWrapSectionsContent(table: HTMLTableElement): voidWraps each section header cell content into a sticky box that keeps the cell content on-screen and centered as much as possible.
Called by init when stickyWrapSectionsContent: true.
offsetTopsForSectionsWhenSideContentSticky(table: HTMLTableElement): voidModify the calculated CSS variables, account for section headers. Only useful when you called stickyWrapSideContent() and have table sections.
Called by init when stickyWrapSideContent: true and stickySections: true | string.
addViewportCssVariables(): voidGenerates the --viewport-width CSS variable. This is the same as 100vw - scrollbar width. Only useful when stickyWrapSectionsContent: true and stickySections: true | string.
Called by init when addViewportWidthVars: true.
addPaddingCssVaraibles(table: HTMLTableElement): voidSet --padding-{top,right,bottom,left} CSS variables on the table element on load. Required by sticky-wrapped cells. Only useful when stickyWrapHeadContent: true, stickyWrapSideContent: true or stickyWrapSectionsContent: true.
Called by init when addPaddingVars: true.
FAQs
Tools to make large HTML table headers and sidebars to stick on the screen when scrolling.
We found that sticky-html-table demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.