Chapter 19 of 34

TableOptions: behaviour and look

Start with all defaults, change only what you need.

  • ⏱ 5 min
  • ▶ Video episode 019
  • git tag ep-019
  • needs @guiexpert/table@1.1.88

After this chapter you can

  • create options with the spread pattern
  • switch hover, borders, resizing, dragging
  • auto-size the columns

The pattern: defaults + your changes

Options are a plain object of type TableOptionsIf. TableOptions contains all defaults; spread it and override only what differs:

src/model/order-table-options.ts
import { TableOptions, type TableOptionsIf } from "@guiexpert/table";
export function createOrderTableOptions(): TableOptionsIf {
return {
...new TableOptions(), // all defaults …
hoverRowVisible: true, // … highlight the row under the mouse
hoverColumnVisible: false, // … but not the column
columnsResizable: true, // drag the column border
columnsDraggable: true, // drag a header to move the column
verticalBorderVisible: false, // calmer look: only horizontal lines
defaultRowHeights: { header: 40, body: 30, footer: 36 } // read by the TableFactory models
};
}
const options = createOrderTableOptions();
const tableModel = TableFactory.createTableModel({ rows: orders, columnDefs, tableOptions: options }); // row heights

TableOptionsIf.defaultRowHeights is read by the factory when it creates the area models – that's why the options go into createTableModel as well as into the TableScope.

Live Own options vs. defaults
Screenshot: Own options vs. defaults Screenshot: Own options vs. defaults
Untick “own options” to see new TableOptions() only. Drag a column border, drag a header to move a column, click “auto-size columns”.

The options you will use most

OptionDefaultEffect
hoverRowVisible / hoverColumnVisibletrue / truehighlight row / column under the mouse
columnsResizabletruedrag the right border of a header cell
columnsDraggabletruedrag a header to move the column
verticalBorderVisible / horizontalBorderVisibletrue / truegrid lines
defaultRowHeightsheader 34, body 34, footer 34row heights of the factory models
externalFilterFunction–chapter 21 (Filtering)
getSelectionModel, getFocusModelone per tablechapter 22 (Selection & copy)
autoRestoreOptionsoffchapter 33 (Persist state)
showCheckboxWihoutExtraColumnfalsechapter 30 (Tree table)
shortcutActionIdMapping, shortcutActionsDisabledOS defaultskeyboard shortcuts

The complete list with descriptions: TableOptionsIf.

Column widths from the content

autoSizeButton.addEventListener("click", () => tableApi.autoResizeColumns());

TableApi.autoResizeColumns() measures the real text of header, body and footer with the font of the table (at most 30 sample rows per column – 100,000 rows take less than half a second).

Next

chapter 20 (Sorting) – by double-click, with own comparators and from code.

API used in this chapter