v1.3.0

Vanilla JS data table

Table, Bro is the Custom Element ‹table-bro›, so a page without a framework creates it as any HTML element: configure() gives it its columns, rows and config, addEventListener() listens to its bro-action events, and the theme attribute sets its theme. Two skins need no framework: Vanilla Bootstrap, the table on the classes and the components of Bootstrap 5, and Vanilla HTML, plain HTML elements, the reference skin to start your own from. The working page is the sample project samples/bootstrap of the repository, built by Vite, and the working page of Vanilla HTML is samples/native; a page without a build takes the same packages from a CDN.

Loading
Items per page:
Clear

How do I install Table, Bro in Vanilla JS?

Install with the MCP server

The quickest start is the MCP server of Table, Bro: add it to your AI coding agent and describe the table you need. The agent installs the packages, generates the table, its setup and its cells, and checks the result. For Claude Code, in the root of the project:

claude mcp add --scope project table-bro -- npx -y @table-bro/mcp@1.3.0

MCP server gives the setup for Codex, Cursor, VS Code and Claude Desktop.

Install manually

The steps of each skin; the code of the table is the same in both.

Vanilla Bootstrap

See a working page

  1. Install the packages

    The table and the parts it needs:

    npm install @table-bro/core @table-bro/bootstrap bootstrap @types/bootstrap
    
  2. Link the CSS

    On the page:

    <link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="node_modules/@table-bro/core/dist/table-bro.min.css">
    <link rel="stylesheet" href="node_modules/@table-bro/bootstrap/dist/table-bro.bootstrap.min.css">
    
  3. Register the skin

    Once, before the tables: the import registers the skin, which takes the classes of Bootstrap. The elements that only some tables use come with their functions: withTags() for tags, withSwitch() for switches; a project that registers the skin already adds the ones of a new table. A page may define them itself, as customElements.define('bro-bs-tags', BroBootstrapTagsComponent).

    import {useBootstrap}      from '@table-bro/bootstrap';
    import {Dropdown, Tooltip} from 'bootstrap';
    
    useBootstrap({Dropdown, Tooltip});
    
Vanilla HTML

See a working page

  1. Install the packages

    The table and the parts it needs:

    npm install @table-bro/core @table-bro/native
    
  2. Link the CSS

    On the page:

    <link rel="stylesheet" href="node_modules/@table-bro/core/dist/table-bro.min.css">
    <link rel="stylesheet" href="node_modules/@table-bro/native/dist/table-bro.native.min.css">
    
  3. Register the skin

    Once, before the tables: the import registers the skin. The elements that only some tables use come with their functions: withTags() for tags, withSwitch() for switches; a project that registers the skin already adds the ones of a new table. A page may define them itself, as customElements.define('bro-nv-tags', BroNativeTagsComponent).

    import '@table-bro/native';
    

With server-side rendering, the steps of Prerender function come after these: prerenderTableBro() renders the table in its loading state into a server DOM.

Without a build

See a working page, StackBlitz

A page without a bundler takes the same packages from jsDelivr, the CDN of npm, at an exact version: the CSS by ‹link›, the modules by an import map, which gives @table-bro/core to the skin and @popperjs/core to Bootstrap (MDN, importmap). index.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Table, Bro + Vanilla Bootstrap without a build</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@table-bro/core@1.3.0/dist/table-bro.min.css" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@table-bro/bootstrap@1.3.0/dist/table-bro.bootstrap.min.css" />
    <!-- The page around the table, as on table-bro.com -->
    <link rel="stylesheet" href="sample-page.css" />
    <script type="importmap">
      {
        "imports": {
          "@table-bro/core": "https://cdn.jsdelivr.net/npm/@table-bro/core@1.3.0/dist/table-bro.esm.js",
          "@table-bro/bootstrap": "https://cdn.jsdelivr.net/npm/@table-bro/bootstrap@1.3.0/dist/table-bro.bootstrap.esm.js",
          "bootstrap": "https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.esm.min.js",
          "@popperjs/core": "https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/esm/popper.min.js"
        }
      }
    </script>
  </head>
  <body>
    <script type="module" src="app.js"></script>
  </body>
</html>

app.js imports the skin, gives it the Dropdown and the Tooltip of Bootstrap, and gives the table its columns, rows and config:

// The import of the skin defines <table-bro> and registers the skin bs, and useBootstrap() gives it the Dropdown and
// the Tooltip of Bootstrap
import {useBootstrap}      from '@table-bro/bootstrap';
import {Dropdown, Tooltip} from 'bootstrap';

useBootstrap({Dropdown, Tooltip});

const cols = [
  {
    title: 'Description',
    name: 'description'
  }, {
    title: 'Price',
    name: 'price',
    dataType: 'number',
    className: 'bro-col_text-right'
  }
];

// The orders of the demos of Docs on table-bro.com
const rows = [
  {description: 'Handcrafted Wooden Table, Gorgeous Bronze Watch, Modern Fresh Salad, Refined Plastic Keyboard, Practical Rubber Shoes', price: 80},
  {description: 'Small Concrete Gloves, Licensed Frozen Pizza, Refined Plastic Keyboard, Modern Fresh Salad, Practical Rubber Shoes', price: 57},
  {description: 'Rustic Cotton Shirt, Ergonomic Steel Chair, Handcrafted Wooden Table, Small Concrete Gloves, Sleek Granite Lamp', price: 13},
  {description: 'Refined Plastic Keyboard, Ergonomic Steel Chair, Modern Fresh Salad, Gorgeous Bronze Watch, Sleek Granite Lamp', price: 27},
  {description: 'Licensed Frozen Pizza, Practical Rubber Shoes, Gorgeous Bronze Watch, Sleek Granite Lamp, Rustic Cotton Shirt', price: 96},
  {description: 'Small Concrete Gloves, Handcrafted Wooden Table, Gorgeous Bronze Watch, Ergonomic Steel Chair, Practical Rubber Shoes', price: 69},
  {description: 'Practical Rubber Shoes, Modern Fresh Salad, Refined Plastic Keyboard, Handcrafted Wooden Table, Gorgeous Bronze Watch', price: 91},
  {description: 'Modern Fresh Salad, Practical Rubber Shoes, Ergonomic Steel Chair, Licensed Frozen Pizza, Gorgeous Bronze Watch', price: 48},
  {description: 'Gorgeous Bronze Watch, Refined Plastic Keyboard, Licensed Frozen Pizza, Ergonomic Steel Chair, Rustic Cotton Shirt', price: 75},
  {description: 'Small Concrete Gloves, Refined Plastic Keyboard, Handcrafted Wooden Table, Rustic Cotton Shirt, Practical Rubber Shoes', price: 97},
  {description: 'Modern Fresh Salad, Refined Plastic Keyboard, Licensed Frozen Pizza, Practical Rubber Shoes, Sleek Granite Lamp', price: 54},
  {description: 'Modern Fresh Salad, Refined Plastic Keyboard, Ergonomic Steel Chair, Practical Rubber Shoes, Handcrafted Wooden Table', price: 99},
  {description: 'Sleek Granite Lamp, Ergonomic Steel Chair, Handcrafted Wooden Table, Gorgeous Bronze Watch, Practical Rubber Shoes', price: 55},
  {description: 'Refined Plastic Keyboard, Sleek Granite Lamp, Modern Fresh Salad, Handcrafted Wooden Table, Ergonomic Steel Chair', price: 81},
  {description: 'Refined Plastic Keyboard, Modern Fresh Salad, Practical Rubber Shoes, Small Concrete Gloves, Rustic Cotton Shirt', price: 86},
  {description: 'Practical Rubber Shoes, Small Concrete Gloves, Refined Plastic Keyboard, Licensed Frozen Pizza, Rustic Cotton Shirt', price: 56},
  {description: 'Rustic Cotton Shirt, Practical Rubber Shoes, Small Concrete Gloves, Ergonomic Steel Chair, Licensed Frozen Pizza', price: 20},
  {description: 'Modern Fresh Salad, Refined Plastic Keyboard, Small Concrete Gloves, Sleek Granite Lamp, Handcrafted Wooden Table', price: 34},
  {description: 'Refined Plastic Keyboard, Modern Fresh Salad, Small Concrete Gloves, Licensed Frozen Pizza, Rustic Cotton Shirt', price: 72},
  {description: 'Ergonomic Steel Chair, Practical Rubber Shoes, Gorgeous Bronze Watch, Rustic Cotton Shirt, Modern Fresh Salad', price: 57}
];

const conf = {
  skin: 'bs',
  toolbarTitle: 'Orders'
};

const table = document.createElement('table-bro');

table.id = 'orders';
table.configure({cols, rows, conf});
table.addEventListener('bro-action', event => console.log(event.detail.action));

// The shadows of the table fall into the margins of this element: the visible table takes its full width
const container = document.createElement('div');

container.className = 'bro-table-shadow-container';
container.append(table);
document.body.append(container);

Which skins can I use?

Table, Bro ships the skins Angular Material, React MUI, Solid SUID, Svelte M3, Vue Vuetify, Vanilla Bootstrap and Vanilla HTML, and a skin of your own design system or UI components is built the same way: Getting started describes the skins, and Your own skin how to build one.

How do I start a skin of my own?

From Vanilla HTML: its plain HTML elements are the parts of a skin with no UI library around them. A skin of your design system takes its config nativeSkinConfig of @table-bro/native, gives the parts of the table your classes or replaces its elements with Custom Elements of your components, and registers it under a name of its own, as registerSkin('brand', brandSkinConfig); on this page conf: {skin: 'brand'} then takes the place of 'nv'. Your own skin describes the config, the elements, the styles and the server render of a skin.

How do I pass cols, rows and conf?

The columns, the rows and the config go to the table in one call, configure({cols, rows, conf}). New rows go by replaceRows(rows), and conf.skin names the registered skin. src/main.ts of the sample imports the skin before the table, and src/orders.ts renders the table:

import type {BroCol, BroConfig, BroRow} from '@table-bro/core';

interface Order extends BroRow {
  description: string;
  price: number;
}

const cols: BroCol<Order>[] = [
  {
    title: 'Description',
    name: 'description'
  }, {
    title: 'Price',
    name: 'price',
    dataType: 'number',
    className: 'bro-col_text-right'
  }
];

// The orders of the demos of Docs on table-bro.com
const rows: Order[] = [
  {description: 'Handcrafted Wooden Table, Gorgeous Bronze Watch, Modern Fresh Salad, Refined Plastic Keyboard, Practical Rubber Shoes', price: 80},
  {description: 'Small Concrete Gloves, Licensed Frozen Pizza, Refined Plastic Keyboard, Modern Fresh Salad, Practical Rubber Shoes', price: 57},
  {description: 'Rustic Cotton Shirt, Ergonomic Steel Chair, Handcrafted Wooden Table, Small Concrete Gloves, Sleek Granite Lamp', price: 13},
  {description: 'Refined Plastic Keyboard, Ergonomic Steel Chair, Modern Fresh Salad, Gorgeous Bronze Watch, Sleek Granite Lamp', price: 27},
  {description: 'Licensed Frozen Pizza, Practical Rubber Shoes, Gorgeous Bronze Watch, Sleek Granite Lamp, Rustic Cotton Shirt', price: 96},
  {description: 'Small Concrete Gloves, Handcrafted Wooden Table, Gorgeous Bronze Watch, Ergonomic Steel Chair, Practical Rubber Shoes', price: 69},
  {description: 'Practical Rubber Shoes, Modern Fresh Salad, Refined Plastic Keyboard, Handcrafted Wooden Table, Gorgeous Bronze Watch', price: 91},
  {description: 'Modern Fresh Salad, Practical Rubber Shoes, Ergonomic Steel Chair, Licensed Frozen Pizza, Gorgeous Bronze Watch', price: 48},
  {description: 'Gorgeous Bronze Watch, Refined Plastic Keyboard, Licensed Frozen Pizza, Ergonomic Steel Chair, Rustic Cotton Shirt', price: 75},
  {description: 'Small Concrete Gloves, Refined Plastic Keyboard, Handcrafted Wooden Table, Rustic Cotton Shirt, Practical Rubber Shoes', price: 97},
  {description: 'Modern Fresh Salad, Refined Plastic Keyboard, Licensed Frozen Pizza, Practical Rubber Shoes, Sleek Granite Lamp', price: 54},
  {description: 'Modern Fresh Salad, Refined Plastic Keyboard, Ergonomic Steel Chair, Practical Rubber Shoes, Handcrafted Wooden Table', price: 99},
  {description: 'Sleek Granite Lamp, Ergonomic Steel Chair, Handcrafted Wooden Table, Gorgeous Bronze Watch, Practical Rubber Shoes', price: 55},
  {description: 'Refined Plastic Keyboard, Sleek Granite Lamp, Modern Fresh Salad, Handcrafted Wooden Table, Ergonomic Steel Chair', price: 81},
  {description: 'Refined Plastic Keyboard, Modern Fresh Salad, Practical Rubber Shoes, Small Concrete Gloves, Rustic Cotton Shirt', price: 86},
  {description: 'Practical Rubber Shoes, Small Concrete Gloves, Refined Plastic Keyboard, Licensed Frozen Pizza, Rustic Cotton Shirt', price: 56},
  {description: 'Rustic Cotton Shirt, Practical Rubber Shoes, Small Concrete Gloves, Ergonomic Steel Chair, Licensed Frozen Pizza', price: 20},
  {description: 'Modern Fresh Salad, Refined Plastic Keyboard, Small Concrete Gloves, Sleek Granite Lamp, Handcrafted Wooden Table', price: 34},
  {description: 'Refined Plastic Keyboard, Modern Fresh Salad, Small Concrete Gloves, Licensed Frozen Pizza, Rustic Cotton Shirt', price: 72},
  {description: 'Ergonomic Steel Chair, Practical Rubber Shoes, Gorgeous Bronze Watch, Rustic Cotton Shirt, Modern Fresh Salad', price: 57}
];

const conf: BroConfig = {
  skin: 'bs', // 'nv' for Vanilla HTML
  toolbarTitle: 'Orders'
};

const table = document.createElement('table-bro');

table.id = 'orders';
table.configure({cols, rows, conf});

// The shadows of the table fall into the margins of this element: the visible table takes its full width
const container = document.createElement('div');

container.className = 'bro-table-shadow-container';
container.append(table);
document.body.append(container);

How do I listen to bro-action?

bro-action is a CustomEvent of the table, whose detail is a BroActionDetail: custom cells, the toolbar, the paginator. table.addEventListener('bro-action', event => console.log(event.detail.action)) logs the name of each action (MDN, CustomEvent).

How do I switch the theme?

The theme attribute or property of the table is 'light', 'dark' or 'auto', which follows the color scheme of the system; the attribute wins over config.theme, 'auto' by default. table.setAttribute('theme', 'dark') switches it, and the table puts the class bro-dark-theme or bro-light-theme on itself, and data-bs-theme of Bootstrap in the skin bs. More in Dark/Light mode.

Questions

Does it need a framework?

No. ‹table-bro› is a Custom Element, a part of the HTML standard that every browser supports (MDN, Using custom elements); the pages of Frameworks render the same element in their templates.

Does it work with server-side rendering?

Yes. The table renders in the browser, and prerenderTableBro() renders it on the server in its loading state into a server DOM, with the elements of the skins bs and nv: Prerender function.

Related

Getting started, Your own skin, Custom content in tables using Custom Elements, MCP server for AI coding agents, Prerender function, Angular data table, Preact data table, React data table, Solid data table, Svelte data table, Vue 3 data table.

DJ