diff --git a/abstract-table.ts b/abstract-table.ts index 047418d..7949cfe 100644 --- a/abstract-table.ts +++ b/abstract-table.ts @@ -17,18 +17,18 @@ export abstract class Table { messageEl: HTMLElement | null; /** - * Creates a list of Header objects to be used in a table for the header cell values and column types. + * Constructs a table based on the parameters given. * @param exampleObject An instance of the type to be displaying. Can be an object with default/zero values for that type * such as `0`, `""`, `false` or `true`. E.g. for a user ```{ id: 0; name: ""; }``` would be passed * @param displayNamesAndOrder A object with the same properties, but all string type for the header cell values. - * Used by passing an object with the keys of R and the name preferred. E.g. for a user: + * Used by passing an object with the keys of {@link TRow} and the name preferred. E.g. for a user: * ```{ id: "ID", name: "Name" }```, this makes the columns appear in the order of ID then Name. - * @param messageElement Used to display messaged related to data output. Optional. + * @param messageElement Used to display messages related to data output. Optional. * Omit (undefined) to use the class provided HTMLParagraphElement. * Pass an HTMLElement to use a custom element. * Pass null to disable automatic message output. */ - constructor(exampleObject: TRow, displayNamesAndOrder?: Record, messageElement?: HTMLElement | null | undefined) { + constructor(exampleObject: TRow, displayNamesAndOrder?: Record, messageElement?: HTMLElement | undefined | null) { this.table = document.createElement("table") this.tableBody = document.createElement("tbody"); @@ -38,15 +38,16 @@ export abstract class Table { this.table.appendChild(this.tableBody); + // If null it means disabled this.messageEl = messageElement === undefined ? document.createElement("p") : messageElement; } /** - * Creates the table headers from the provided example object and the headers orders and names if provided (otherwise inferred) + * Creates a list of {@link Header} objects to be used in a table for the header cell values, column types, and header/column order (if provided, otherwise inferred). * @param exampleObject An example object of TRow, e.g. User = { id: 0, name: "Name"}. Used to store the types for each column. * @param displayNamesAndOrder The order and names of the columns on the table. * e.g. User = { fullname: "Full Name", id: "User ID" }, the headers would be "Full Name" and "User ID" in column order and headers, - * @return A array of {@link Header} type shape that holds the header/column info. + * @return An array of {@link Header} type shape that holds the header/column info. */ createHeadersFromType( exampleObject: TRow, // Needed for runtime, since types don't exist in JS. @@ -80,7 +81,7 @@ export abstract class Table { thead.appendChild(headerRow); this.table.appendChild(thead); } - + /** * Returns the table element of this instance for putting onto a page. */