Interface ColumnDefIf

Describes one column: which property it shows, header label, width, CSS classes, renderers, sorting, editing and visibility. Create it with ColumnDef – new ColumnDef(property, label, width, classes) or ColumnDef.create with named parameters.

Column indices (e.g. in AreaModelIf.getValueAt) are positions in the columnDefs array – fixed columns and hidden columns included.

Example

const columnDefs: ColumnDefIf[] = [
new ColumnDef("id", "ID", px80, allRight),
ColumnDef.create({
property: "total", headerLabel: "Total", width: px120,
headerClasses: ["ge-table-text-align-right"], bodyClasses: ["ge-table-text-align-right"],
sortable: TrueFn, sortState: "desc"
})
];

See

Training: Columns with ColumnDef

Hierarchy

  • ColumnDefIf

Implemented by

Properties

cellFormulas?: boolean

false: this column never holds cell formulas (TableOptionsIf.cellFormulas) – "=…" stays text (free text, notes). Default: every data column of a table with cellFormulas.

Example

ColumnDef.create({ property: "note", editable: TrueFn, cellFormulas: false })

Since

1.1.99

classes: AreaObjectMapType<string[]>

CSS classes per area – classes.header, .body, .footer. The constants bodyLeft, allRight … are ready-made maps for the alignment.

editInputPipe?: editInputPipe

Converts the text of the editor before it is written into the model, e.g. editInputPipeForNumber.

editable?: BooleanFunction

The cells of this column can be edited (double-click or F2), e.g. TrueFn.

See

Training: Inline editing

The editor of this column in Excel-style editing (TableOptionsIf.editing): "text", "number", "date" or a factory for an own CellEditorIf. Without it the table chooses by the value (numbers → number editor, dates → date editor, otherwise text). A column with an own getEditRenderer keeps that editor (inside the cell, as before).

Example

ColumnDef.create({ property: "status", editable: TrueFn, editor: () => SelectCellEditor.create(["open", "paid"]) })

Since

1.1.99

emptyValue?: unknown

The value a cleared cell gets (Delete/Backspace in Excel-style editing), e.g. null or 0. Default: EditingOptionsIf.emptyValue ("").

Example

ColumnDef.create({ property: "quantity", editable: TrueFn, emptyValue: 0 })

Since

1.1.99

formula?: string

The formula of a formula column (ColumnDef.create({ formula }) compiles it into the valueGetter), e.g. "[price] * [quantity] * 1.19". Informational – change it with TableApi.setColumnFormula.

getEditRenderer?: GetEditRenderer

The editor of this column. Default: TableOptions.getEditRenderer (a text input, InputCellRenderer).

Example

getEditRenderer: () => new SelectCellRenderer(["open", "paid"].map(s => new ValueLabel(s, s)))
headerLabel: string

Text of the header cell (used when the header is built from the column definitions).

isVisible?: BooleanFunction

Whether the column is shown. Hidden columns are not rendered, copied or exported.

Example

ColumnDef.create({ property: "category", headerLabel: "Category", isVisible: FalseFn })
maxWidth: SizeIf

Upper limit for percentage widths ("%"). Not applied to pixel widths or to resizing with the mouse.

minWidth: SizeIf

Lower limit for percentage widths ("%"). Not applied to pixel widths or to resizing with the mouse.

property: string

Property of the row object shown in this column ("customer"). With nested objects a path like "address.city".

Cell renderers per area – rendererMap.header, .body, .footer. Without a renderer the value is shown as text.

Example

column.rendererMap.body = new NumberCellProgressBarCellRenderer(20, false);
column.rendererMap.footer = new EuroRenderer(); // an own CellRendererIf

See

Training: Cell renderers

Row drag: the body cells of this column get a drag handle (true, or a function that decides per row – e.g. no handle for locked rows). Dragging the handle moves the row (see TableOptionsIf.rowDragOptions); the keyboard alternative is Ctrl+Alt+↑/↓. TableFactory.createTableModel({ rows, rowDrag: true }) sets it on the first data column.

Example

ColumnDef.create({ property: "title", headerLabel: "Task", rowDrag: (task: { locked: boolean }) => !task.locked })

Since

1.1.95

showValuesAs?: ShowValuesAsConfig

Shows the numbers of the column differently without changing the data: share of the column total, running total, rank … (see ShowValuesAs). Change it at runtime with TableApi.setShowValuesAs.

Example

ColumnDef.create({ property: "total", headerLabel: "Share", showValuesAs: "percentOfColumnTotal" })

See

Training: Show values as

Since

1.1.95

sortComparator?: ValueRowSortComparator

Own comparison of two cell values (and their rows), like for Array.prototype.sort.

Example

sortComparator: (a: string, b: string) => a.localeCompare(b, "de")     // "Müller" before "Nordlicht"

See

Training: Sorting

sortIconVisible?: BooleanFunction

Show the sort icon in the header. Default: follows sortable resp. sortState.

sortState?: SortState

The sort icon shown in the header: "asc", "desc" or "" (none). It only sets the icon – sort the rows once with TableModelIf.doSort to match it.

sortStatesOrder?: SortState[]

Order of the sort states on repeated double-clicks. Default: TableOptions.sortOrder (["asc", "desc"]).

sortable?: BooleanFunction

The column can be sorted by a double-click on its header (e.g. TrueFn).

validate?: CellValidator<any>

Checks an edited, filled or pasted value (after editInputPipe): return a message for an invalid value, undefined for a valid one. Batch edit: invalid values are marked (ge-table-cell-invalid, the message as tooltip) and block TableApi.commitBatchEdit; otherwise an invalid value is not written.

Example

ColumnDef.create({
property: "price", headerLabel: "Price", editable: TrueFn, editInputPipe: editInputPipeForNumber,
validate: (value: unknown) => typeof value === "number" && value >= 0 ? undefined : "A price is a number ≥ 0",
})

Since

1.1.96

valueGetter?: ValueGetter

A calculated column: computes the value from the row instead of reading property (the data stays unchanged). Sorting, filter (TableApi.getRowValue), copy, Excel, totals (footerAggregates) and row groups use the computed value. property stays the id of the column (state, footerAggregates, other formulas). Without a ColumnDefIf.valueSetter the column cannot be edited.

Supported by the models of TableFactory.createTableModel({ rows }), trees, row groups (not by array-of-arrays models; an own AreaModel calls it itself).

Example

ColumnDef.create({ property: "total", headerLabel: "Total", sortable: TrueFn,
valueGetter: (o: Item) => o.price * o.quantity })

See

Live demo: formulas & calculated columns · Training: Calculated columns, “Show values as” and formulas

Since

1.1.95

valueSetter?: ValueSetter

Makes a calculated column editable: writes the edited value back into the row (return false to reject).

Example

valueSetter: (o: Item, v: unknown) => { o.price = Number(v) / o.quantity; }

Since

1.1.95

width: SizeIf

Width of the column: px120, new Size(10, "%") or new Size(1, "weight"). See SizeUnitType.