Taking an input of data and options, return a html Element
which can then be inserted into the DOM. This is a tool used on my website to generate certain tables.
const renderTarget = document.getElementsByClassName('renderTarget')[0];
const myData = [
{ complete: false, description: "Foo" },
{ complete: true, description: "Bar" }
]
renderTarget.append(
renderTable<{complete: boolean, description: string}>({
sortable: true,
data: myData,
columns: [
{
header: '?',
accessor: 'complete',
renderer: (value) => (value ? 'X' : ''),
},
{
header: 'Description',
accessor: 'description',
},
],
}),
);
/** Renders the following HTML Table:
* | ? | Description |
* | --- | ----------- |
* | | Foo |
* | X | Bar |
*/
Allows the table to be sortable, will auto-wrap the table in a createSortableTable()
call. This is exported for other tables, it takes an input of Element
and returns void
. Calling will add click handlers & functions to the table.
Apply a class to every cell in the column