Skip to content

Generate a HTML element based of a config & data object

Notifications You must be signed in to change notification settings

pfych/pfych-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Table Renderer pfych-table

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.

Example

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         |
 */

Optional Properties

Table: sortable?: boolean

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.

Column: className?: string

Apply a class to every cell in the column

About

Generate a HTML element based of a config & data object

Resources

Stars

Watchers

Forks

Packages

No packages published