A built-in column with running row numbers (1, 2, 3 …) like the row headers of a spreadsheet.

The easy way is the factory flag: TableFactory.createTableModel({ rows, rowNumbersVisible: true }) puts this column in front of the others and fixes it on the left. Put it into columnDefs yourself if you build the models yourself – as the first column, counted in fixedLeftColumnCount.

What the table does with it:

  • the width follows the largest number ("9" → "2000000") – after setRows, filtering, expanding tree rows;
  • not sortable, not editable, no resize handle, can't be dragged, no column can be dragged in front of it;
  • body cells have role="rowheader" – screen readers announce the number with the row;
  • a click on a number selects the row (selection type "row" and "range"), Shift extends, Ctrl/⌘ toggles; a click on the header cell selects all;
  • copy (TableApi.copyToClipboard) and Excel export (TableApi.downloadExcel) leave it out, unless exported: true;
  • with a CheckboxColumnDef directly behind it, the checkbox, the tree arrow and showCheckboxWihoutExtraColumn move one column to the right.

Note: it is a real column – the indices of all other columns are one higher (like with a CheckboxColumnDef). Use properties where you can (tableApi.setColumnVisible("total", false), TableApi.getColumnIndex).

Example

const withNumbers: ColumnDefIf[] = [new RowNumberColumnDef(), new CheckboxColumnDef(), ...columnDefs];
const model = TableFactory.createTableModel({ rows: orders, columnDefs: withNumbers, fixedLeftColumnCount: 2 });

See

Training: Fixed columns

Since

1.1.93

Hierarchy

  • RowNumberColumnDef

Implements

Constructors

Properties

classes: AreaObjectMapType<string[]> = ...

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

headerLabel: string

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

isVisible: BooleanFunction = TrueFn

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.

The options (defaults from RowNumberOptions).

property: string = "RowNumberColumn"

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

type: "RowNumberColumnDef" = "RowNumberColumnDef"

Marker for isRowNumberColumnDef (works across copies of the core).

width: SizeIf

Starts with minWidthInPx; the table widens it to fit the largest number.

Methods

  • The number of a body row (1-based): its position in the view ("display") or in getAllRows() ("original").

    Parameters

    • rowIndex: number

      row index in the body (the current view)

    • bodyModel: AreaModelIf

      the body model

    Returns number

    the row number

    Example

    const columnDef = new RowNumberColumnDef();
    const rowNumber = columnDef.getRowNumber(0, tableModel.getBodyModel()); // 1
  • The text of a row number: options.format(getRowNumber(…)).

    Parameters

    • rowIndex: number

      row index in the body

    • bodyModel: AreaModelIf

      the body model

    Returns string

    the text shown in the cell (and exported with exported: true)

    Example

    const columnDef = new RowNumberColumnDef({ format: n => n.toLocaleString("en-US") });
    const text = columnDef.getRowNumberText(1999, tableModel.getBodyModel()); // "2,000"
  • The text of the largest number the column can show now – the table measures it for the column width. "display": the row count; "original": the count of all rows (unfiltered). At least the text of 1.

    Parameters

    Returns string

    e.g. "2000000"

    Example

    const widest = new RowNumberColumnDef().getWidestText(tableModel.getBodyModel()); // "1000" for 1000 rows
    
  • True if the numbers are shown without an own format (plain digits) – the Excel export then writes numbers.

    Returns boolean

    false with an own options.format

    Example

    const plain = new RowNumberColumnDef().hasDefaultFormat(); // true