0.4.0 • Published 3 years ago
@buckneri/table v0.4.0
table
My take on building a more interactive HTML table. The build includes a starter CSS file, and two javascript versions for ES modules and current browsers. No serious attempt has been made towards ie11 compatibility.
Installation
npm i --save @buckneri/table
API
Constructor
const table = new Table({
container: document.getElementById("table"),
data: {
headers: [{ value: "uuid", sort: false }, { value: "name", sort: true }],
rows: [
[{ value: 1 }, { value: "Robert" }], [{ value: 2 }, { value: "Jane" }]
]
},
locale: "en-GB",
rows: 10
});
Events
"row-selected"
// emitted when table row is selected
Methods
table.data(data);
// stores and initialises data
table.destroy();
// self-destruct
table.draw();
// draws table to DOM
table.rowClickHandler();
// actions performed on row click
table.sortHandler();
// actions performed on column sort
table.toString();
// serialises the internal data
Properties
table.container
// parent element for table
table.locale
// locale code e.g. en-GB
table.rows
// number of rows to display