Active Table
repository·main·Indexed 43 days ago
https://github.com/ovidijusparsiunas/active-tableA framework-agnostic web component for building editable tables and complex real-time data grids. Version 1.1.8 supports row/column management, pagination, and built-in data types including Currency, Date, and Checkbox. It features comprehensive file import/export capabilities for csv, xls, xlsx, ods, and txt formats, as well as a dedicated React wrapper.
What's inside Active Table
- Active Table is a web component designed to provide a highly customizable and editable table experience. It is built to handle diverse data requirements—such as categorical, partial augmentation, or exclusively numerical data—through an extensive API. The component is designed to be cross-framework and 'plug and play', allowing for quick integration into various web development environments.
Overview of Active Table features
mainActive Table is a customizable web component for editable tables and real-time data visualization. Key capabilities include:
- Row/Column Management: Add, remove, move, and edit rows and columns (including mouse-based dragging).
- Data Types: Built-in support for Text, Number, Currency, Select, Label, Date, and Checkbox columns.
- Data Manipulation: Sorting, pagination, filtering, and programmatic cell updates.
- File Support: Import, export, paste, and drag-and-drop support for
csv,xls,xlsx,ods, andtxtfiles. - Extensibility: API for building custom column types and full UI customization.
Handle narrow columns with `preserveNarrowColumns`
mainWhen the table has a fixed
widthormaxWidth(viatableStyle), adding new columns normally shrinks existing columns.preserveNarrowColumns: true(Default): If columns reach a minimum width of 33px and cannot be shrunk further, the table width will automatically increase to accommodate new columns.preserveNarrowColumns: false: If columns reach the 33px limit, no new columns will be allowed to be inserted.
Note: If
tableStyleuses%orvwunits, the table will not remove excess columns even ifpreserveNarrowColumnsisfalsewhen the window is resized, to prevent data loss.<ActiveTable preserveNarrowColumns={true} tableStyle={{ width: '300px' }} data={[['1', '2', '1', '2'], ['val', 'val', 'val', 'val']]} />Supported file formats and dependencies
mainActive Table supports importing and exporting the following file formats:
csv(supported natively)xlsxlsxodstxt
Important: If you intend to use any format other than
csv(such asxls,xlsx, orods), you must add thexlsxmodule to your project.Use stateful CSS styling for elements
mainThe project provides several types for applying CSS styles based on element states:
StatefulCSS: Defines styles for different mouse states:default,hover, andclick. Each state accepts aCSSStyleobject.HoverableStyles: A specialized type for hover effects. It includes adefaultstate (usingNoDimensionCSSStyle) and ahoverColorsobject which only acceptsbackgroundColorandcolorproperties.NoDimensionCSSStyle: A subset ofCSSStylethat excludes all dimension-related properties (width,minWidth,maxWidth,height,minHeight,maxHeight).
Observe ActiveTable events
mainYou can observe events in ActiveTable using two different methods:
- Property Assignment: Assign a callback function directly to the corresponding property on the table element (e.g.,
tableElementRef.onCellUpdate = ...). - Custom Event Listeners: Use the standard
addEventListenermethod to listen for custom events fired from the element (e.g.,tableElementRef.addEventListener('cell-update', ...)).
Warning: When using event information to update a parent state, take care not to trigger an infinite re-render loop of the component.
- Property Assignment: Assign a callback function directly to the corresponding property on the table element (e.g.,
Quickstart with Active Table
mainOnce installed, you can render a table by adding the
<active-table>web component to your markup. You can pass initial data using thedataattribute as a JSON string representing a 2D array (where the first array contains headers).Note: The exact syntax for passing data may vary depending on your specific framework (React, Vue, Angular, etc.).
<active-table data='[["Planet", "Diameter"], ["Earth", 12756]]'/>Enable Excel and other file formats in Active Table
mainActive Table supports importing and exporting
csv,xls,xlsx,ods, andtxtfiles. Whilecsvis supported natively, all other formats require thexlsxmodule to be available on the globalwindow.XLSXobject.You must provide the
xlsxmodule to the environment using one of the following methods to enable advanced file support.import * as xlsx from "xlsx"; window.XLSX = xlsx;Add XLSX types for TypeScript
mainWhen using TypeScript, you must declare the
XLSXproperty on the globalWindowinterface to avoid compilation errors when assigning the module towindow.XLSX.import * as xlsx from 'xlsx'; declare global { interface Window { XLSX: typeof xlsx; } }Access active-table via CDN
mainYou can include
active-tabledirectly in your project using a CDN link without a package manager:https://unpkg.com/active-table@1.1.8/dist/activeTable.bundle.jsUse ActiveTable in Svelte
mainActiveTable works out of the box with Svelte version
4.2.2or above.For older Svelte versions: Properties that use camelCase names (e.g.,
myProperty) must be passed as stringified attributes in the markup.Configure XLSX module via dependency manager
mainIf you are using a package manager like npm, you can provide the
xlsxmodule to Active Table by importing it and assigning it towindow.XLSX.// Static import import * as xlsx from "xlsx"; window.XLSX = xlsx;// Dynamic import import("xlsx").then((module) => { window.XLSX = module; });