Table

Mode

Skin

Theme

Overview & Philosophy

Applied to a table container via <div data-ln-table id="..."> or <table>, ln-table operates in two distinct modes. In SSR mode, it indexes server-rendered <tbody> rows, intercepting ln-search, ln-filter, and ln-sort CustomEvents to toggle .hidden on <tr> elements or reorder rows in the DOM. In data-driven mode (data-ln-table-source="store"), it listens for ln-data-store:data events, clones <template data-ln-table-row>, populates cells via fill(), and mounts rendered rows into <tbody> with sliding-window virtual scrolling.

In web application design, data grids can often be pre-rendered completely on the server. In these scenarios, introducing a heavy client-side JSON-to-HTML template rendering pipeline is unnecessary overhead. The DOM already contains the correct HTML rows on initial load.

Instead of generating rows dynamically, ln-table parses existing DOM rows directly on paint. It layers ultra-fast, in-memory client-side sorting, column filtering, text searches, and virtual scroll on top of standard pre-rendered HTML, providing a fluid desktop-grid experience with zero database fetching overhead.

The Server-Rendered Integration

Unlike data tables (which consume raw JSON via event streams), ln-table expects standard rows (<tr>) already printed in <tbody> on page load. It acts as an upgrade node: parsing cell texts dynamically and hiding or sorting DOM elements in-place. The HTML DOM is the single source of truth.

Three Orthogonal Layers of HTML Table Enhancements

  1. The Pre-Rendered Markup (HTML DOM): Rows arrive completely rendered from the server. Cells can contain rich markup (links, pills, or custom badges) natively on initial paint.
  2. The Visual Class Hooks (CSS State): Visual indicators (such as sort states or popover filters) are managed by standard CSS classes. The button markup contains static icons; CSS manages what is shown.
  3. The Parsing Shell (ln-table): The script acts as an enhancement node. It scans cells, parses raw values (using optional data-ln-value attributes), manages in-memory sort orders, and hides rows dynamically using filter criteria.

How the Local Search and Sort Coherence Works

  1. On load, the script parses every row, mapping text strings or custom data-ln-value targets into highly-optimized search and sort indexes in memory.
  2. When a user types in a connected search bar (data-ln-search-for) or clicks a sort header (data-ln-sort), the component executes in-memory, local array filters instantly.
  3. The component updates table rows in-place (toggling visibility or re-ordering nodes in the DOM). If the visible row count exceeds 200, it automatically activates virtual scrolling.

For the full guide see the ln-table README and the architecture reference.

Attributes

AttributeOn elementDescription
data-ln-tablewrapper (needs id)Component root. Parses rows, listens for events.
data-ln-search-for="tableId"<input> or wrapperControl pointer to table ID. ln-table intercepts the event for in-memory filtering.
data-ln-table-clear<button>Clears search input.
data-ln-sort="tableId"<ul> inside <th>Sort control. Type is auto-detected at sort time — no type attribute needed.
td[data-ln-value]<td>Raw sort value when display text differs.
data-ln-table-filter-col="key"<th>Maps column to a filter key (used by ln-filter).
data-ln-table-empty<template>Content shown when filter returns 0 results.

Live Demo — 20 rows with search, sort and filter

Products

#
Product
Category
Price
Stock
Status
1Laptop Pro 15Electronics1499120In Stock
2Wireless Mouse M1Peripherals29450In Stock
3USB-C Hub MultiportPeripherals5985In Stock
4Mechanical Keyboard RGBPeripherals12940Low Stock
5Monitor 27" 4K UHDElectronics49915Low Stock
6Webcam HD 1080pPeripherals790Out of Stock
7Headset Pro WirelessAccessories199210In Stock
8Docking Station Dual 4KAccessories24960In Stock
9SSD 1TB NVMe PCIe4Storage119310In Stock
10RAM 32GB DDR5 KitComponents15995In Stock
11GPU Card RTX 4070Components6998Low Stock
12Network Switch 24-PortNetworking29922Low Stock
13Power Supply 850W GoldComponents139140In Stock
14Cable Kit Modular sleeveAccessories39500In Stock
15Mouse Pad XL Desk MatAccessories190Out of Stock
16Screen Protector 27"Accessories25180In Stock
17Router Wi-Fi 6E ProNetworking22945Low Stock
18External HDD 4TB USB3Storage99120In Stock
19Microphone USB StudioAccessories14975In Stock
20Ergonomic Office ChairAccessories34912Low Stock
Total Products: 20

Events

EventDispatched bydetail
ln-table:readyln-table — after row parse{ total }
ln-table:filterln-table — after filter render{ term, matched, total }
ln-table:sortedln-table — after sort render{ column, direction, matched, total }
ln-table:emptyln-table — filter returns 0{ term, total }

data-ln-value — sort raw value

When display text differs from the sort key:

<!-- Without: sorts by "1.250" (string) -->
<td>1.250</td>
 
<!-- With: sorts by 1250 (number) -->
<td data-ln-value="1250">1.250</td>
 
<!-- Date: sorts by Unix timestamp -->
<td data-ln-value="1700000000">15.11.2023</td>

Virtual Scroll

Activates when filtered rows exceed 200. Renders only visible rows + 15 buffer rows above/below. Deactivates automatically when rows drop below threshold. Column widths are locked on first parse to prevent layout shifts.

Dynamic Rows (AJAX)

If <tbody> is empty at init, a MutationObserver waits for rows to appear and parses them automatically.

API

// Manual init
window.lnTable(document.body);

// Instance
var el = document.querySelector('[data-ln-table]');
el.lnTable.destroy();   // remove listeners, virtual scroll, column locks