🔨 Lightweight and simple data table with no dependencies
- ✅ Display any data (array with objects) in simple table layout
- ✅ Support custom skins (style children of
div.simple-data-table
) - ✅ Small size of package
- ✅ No dependencies
- ✅ Support custom events (
on
,emit
)- Updated cell content
- Row removed
- Row added
- Sorted table
- ✅ Fluent API (not available in all public methods)
- ✅ API
- Lazy loading of data (
load()
) - Read number of rows (
getRowsCount()
) - Get content from concrete cell (
getCell
) - Find cells which contains concrete text (
findCellsByContent()
) - Highlight cells (
highlightCell
,clearHighlightedCells()
) - Support put value into single cell (
setInputCellContent()
) - Sorting by a concrete cell with a given function (
sortByColumn()
&setSortComparingFn
) - Define headers, as a first row (
setHeaders()
)
- Lazy loading of data (
- ✅ Readonly Mode
npm install simple-data-table
<link rel="stylesheet" href="src/skins/default.css"/>
<script src="src/index.js"></script>
const $container = document.querySelector('#place-to-render');
const options = { /* all available options are described below */ };
const t = new SimpleDataTable($container, options);
t.load([
{
column1: 'Cell 1',
column2: 'Cell 2',
column3: 'Cell 3'
},
{
column1: 'Cell 4',
column2: 'Cell 5',
column3: 'Cell 6'
},
{
column1: 'Cell 7',
column2: 'Cell 8',
column3: 'Cell 9'
},
{
column1: 'Cell 10',
column2: 'Cell 11',
column3: 'Cell 12'
}
]);
t.render();
https://piecioshka.github.io/simple-data-table/demo/
Change value od button which add new row.
const t = new SimpleDataTable($container, {
addButtonLabel: 'New record'
});
t.load(...);
t.render();
Define what "name" should have cells in new added columns.
const t = new SimpleDataTable($container, {
defaultColumnPrefix: 'random'
});
t.load(...);
t.render();
Define how much columns should contain row in empty table.
By default, use the size of headers or the number of cells in the first row.
const t = new SimpleDataTable($container, {
defaultColumnNumber: '7'
});
t.load(...);
t.render();
Define class of highlighted cell.
const t = new SimpleDataTable($container, {
defaultHighlightedCellClass: 'my-highlight'
});
t.load(...);
t.render();
Define class of highlighted cell.
const t = new SimpleDataTable($container, {
readonly: true
});
t.load(...);
t.render();
Render table into DOM.
Get number of rows.
Get list of cell positions which contains passed strings.
Get DOM reference of concrete cell.
Add class to concrete cell.
Remove CSS class of all highlighted cells.
Put content into input in concrete cell.
Setup column headers. Sorting is enabled by default.
Loading data into table component.
Trigger event on SimpleDataTable instance.
Listen on events.
Sorts data and triggers DATA_SORTED
event.
WARNING: Function sortByColumn()
runs render()
under the hood.
Set _sortComparingFn()
which by default use String.prototype.localeCompare
.
Event is dispatching when you change any of input in table.
const t = new SimpleDataTable($container);
t.on(SimpleDataTable.EVENTS.UPDATE, (data) => {
// do some stuff with the updated data...
});
Event is dispatching when you add new record.
const t = new SimpleDataTable($container);
t.on(SimpleDataTable.EVENTS.ROW_ADDED, () => {
// do some stuff...
});
Event is dispatching when you remove any record.
const t = new SimpleDataTable($container);
t.on(SimpleDataTable.EVENTS.ROW_REMOVED, () => {
// do some stuff...
});
Event is dispatching after data is sorted with sortByColumn
function.
const t = new SimpleDataTable($container);
t.on(SimpleDataTable.EVENTS.DATA_SORTED, () => {
// do some stuff...
});
Recursive remove children from passed HTMLElement.
- Safari v10.1.2
- Firefox v61.0.1
- Chrome v67.0.3396.99
- Opera v51.0.2830.40
The MIT License @ 2018