import '../pagination/pagination.js'; import { UiElement } from '../shared/element.js'; import type { TableAllSelectedDetail, TableCellEditDetail, TableCsvExportDetail, TableColumnResizeDetail, TableColumnsChangeDetail, TableCsvScope, TablePageChangeDetail, TableExpandoDetail, TableFilteredDetail, TableHeaderCellSortDetail, TableRowSelectedDetail, TableSelectionDetail, TableSize, TableSortedDetail } from './defs.js'; import { UiTableHeaderCell } from './table-header-cell.js'; import type { UiTableRow } from './table-row.js'; import './table-cell.js'; import './table-head.js'; import './table-header-row.js'; import './table-row.js'; import './table-expanded-row.js'; import './table-header-title.js'; import './table-header-description.js'; import './table-toolbar.js'; import './table-toolbar-content.js'; import './table-toolbar-search.js'; import './table-batch-actions.js'; import './table-skeleton.js'; import './table-column-settings.js'; import './table-csv-export.js'; export * from './defs.js'; export { UiTableBody } from './table-body.js'; export { UiTableCell, type UiTableCellEventMap } from './table-cell.js'; export { UiTableHead } from './table-head.js'; export { UiTableHeaderCell, type UiTableHeaderCellEventMap } from './table-header-cell.js'; export { UiTableHeaderRow, type UiTableHeaderRowEventMap } from './table-header-row.js'; export { UiTableRow, UiTableRowBase, type UiTableRowEventMap } from './table-row.js'; export { UiTableExpandedRow } from './table-expanded-row.js'; export { UiTableHeaderTitle } from './table-header-title.js'; export { UiTableHeaderDescription } from './table-header-description.js'; export { UiTableToolbar } from './table-toolbar.js'; export { UiTableToolbarContent } from './table-toolbar-content.js'; export { UiTableToolbarSearch } from './table-toolbar-search.js'; export { UiTableBatchActions, type UiTableBatchActionsEventMap } from './table-batch-actions.js'; export { UiTableSkeleton } from './table-skeleton.js'; export { UiTableColumnSettings } from './table-column-settings.js'; export { UiTableCsvExport, type UiTableCsvExportEventMap } from './table-csv-export.js'; /** * Carbon `cds-table`: a table built from elements — `` with a `` of * ``s, and `` with ``s of ``s. CSS table * layout (the columns line up as in a ``), `role=table` / `rowgroup` / `row` / `columnheader` / `cell`. * * Sizes xs / sm / md / lg (default) / xl, `use-zebra-styles`, `use-static-width` (as wide as its content). * * Sorting (`is-sortable`, or `is-sortable` on single headers): a header click steps its `sort-direction` * through its `sort-cycle`, the other headers go back to none, and the table moves the body's rows into * that order (an expanded row moves with the row before it), then fires `ui-table-sorted`. A cell sorts by * its `sort-value`, else its text: numbers by value, text by `locale` (default: the page's `lang`); * `customSortRow` replaces the comparison. None restores the order the rows came in. Sorting keeps the * focus and the scroll position. * * Rows rendered by a framework (React, Vue): call `preventDefault()` on `ui-table-header-cell-sort`, sort * the data, render the rows in that order and set the header's `sort-direction` — moving rows a framework * owns makes its later updates go wrong. * * Selection (`is-selectable`, or `radio` for one row): every row gets a checkbox (radio) cell and the header * row a select-all checkbox — checked while rows are chosen, partly while only some are; clicking it then * releases them all. Choices fire `ui-table-row-selected` / `ui-table-row-all-selected`; a `` * in the toolbar shows the count and Cancel while rows are chosen. Disabled rows can't be chosen; select-all * takes only the rows the search shows. Radio rows take one Tab stop and the arrow keys. * * Title and toolbar (Carbon TableContainer / TableToolbar): ``, * `` and ``. Typing in a * `` leaves out (`filtered`) the rows whose text doesn't contain it — `filterRows` * replaces the test — and fires `ui-table-filtered`; the zebra stripes follow the rows shown. * * Expansion (`expandable`): a `` right after a row makes it expandable — a chevron cell * opens it underneath; `batch-expansion` puts an expand-all chevron in the header row. * * Paging (no Carbon counterpart on the table; Carbon pages with a separate Pagination): `page-size` adds a * `` under the table that shows that many of the rows the sort and search leave (`page`, * `page-sizes`; `ui-table-page-change`). Select-all then takes the page, and the batch bar offers "Select all (N)" * for every row the search shows. Server paging: give the table one page of rows and use your own ``. * * Columns (no Carbon counterpart): a `` in the toolbar hides and shows columns * (`ui-table-columns-change`; `hiddenColumns`, `setColumnHidden()`, `resetColumns()`); the search skips hidden * columns. `pinned` on the first / last header keeps that column in view while the table scrolls sideways (a * pinned first column takes the chevron and checkbox columns with it). `resizable` puts a resize handle on every * header: the first resize freezes the columns at their widths and an empty filler cell takes the rest of the row. * * Editing (no Carbon counterpart; the WAI-ARIA APG grid): `editable="text|number|select"` on a header lets its cells * be edited in place. The table becomes a grid with one Tab stop among the body cells (arrow keys, Home / End); * Enter, F2, typing or a double click opens a cell's editor, Enter saves, Escape cancels, Tab saves and goes to the * next editable cell. Saving fires a cancelable `ui-table-cell-edit` from the cell, then writes the value into it. * * CSV (no Carbon counterpart): a `` in the toolbar downloads the rows the search shows; * `toCsv({ scope })` / `downloadCsv({ scope, fileName })` export `'shown'`, `'selected'` or `'all'` rows. * * Loading and empty (Carbon's DataTable leaves both to the app): `loading` shows skeleton rows in the columns * (`loading-rows`, default the rows shown, else the page size, else 5) with the table `aria-busy`. With no rows * the table shows the `empty` slot ("No data"), or `no-results` ("No results found…") while the search leaves none. * * Differs from Carbon web components, which: sort numbers as text ("10" before "9"); leave none in no set * order; sort the rows even when the event was canceled; set no `aria-sort`; give the checkbox and chevron * cells no role; and keep zebra stripes on rows the search hid. * * @slot - `` and `` * @slot title - A `` * @slot description - A `` * @slot toolbar - A `` * @slot empty - Shown when there are no rows (default: "No data") * @slot no-results - Shown when the search leaves no rows (default: "No results found. Try a different search.") * @csspart header - The title / description block * @csspart content - The horizontal scroll container * @csspart table - The box laid out as a table * @csspart empty - The message under the headers when there are no rows * @fires ui-table-sorted - detail: { sortedHeader } after the rows were sorted by a header click * @fires ui-table-row-selected - detail: { selectedRow, selectedRows } after the user chose or released a row * @fires ui-table-row-all-selected - detail: { selectedRows } after select-all or Cancel * @fires ui-table-filtered - detail: { unfilteredRows } after the search changed which rows show * @fires ui-table-page-change - detail: { page, pageSize } after the built-in pagination changed (`page-size`) * @fires ui-table-cell-edit - from the cell, cancelable; detail: { row, cell, column, value, previous } before an edited value is written into the cell (`preventDefault()` to write it yourself) * @fires ui-table-columns-change - detail: { hiddenColumns, column, hidden } after a column was shown or hidden (`column` is '' after Reset) * @csspart pagination - The built-in `` (`page-size`) * @cssprop --ui-table-max-height - Height of the scrolling box with `sticky-header` (default 300px) * @cssprop --ui-table-row-height - Row height of the default size, lg (default 48px; Kanok: 40px) * @cssprop --ui-table-border / --ui-table-radius / --ui-table-overflow - A frame around the table (default none, 0, visible; Kanok: none, 12px, clip) * @cssprop --ui-table-background - Fill of the table: its title, toolbar and rows (default transparent, rows `--ui-surface-1`; Kanok: the cards' fill) * @cssprop --ui-table-header-rule - `box-shadow` under the header cells (default none; Kanok: a hairline) */ export declare class UiTable extends UiElement { static readonly styles: import("lit").CSSResult[]; size: TableSize; /** Every header sorts the rows (Carbon `is-sortable`). */ isSortable: boolean; /** Stripe every second body row (Carbon `use-zebra-styles`). */ useZebraStyles: boolean; /** As wide as its content instead of its container (Carbon `use-static-width`). */ useStaticWidth: boolean; /** The language text sorts in; empty: the page's `lang`. */ locale: string; /** A checkbox on every row and select-all in the header row (Carbon `is-selectable`). */ isSelectable: boolean; /** One row at a time, with radios (Carbon `radio`). */ radio: boolean; /** Rows followed by a `` open it with a chevron (Carbon `expandable`). */ expandable: boolean; /** An expand-all chevron in the header row (Carbon `batch-expansion`). */ batchExpansion: boolean; /** The title / description block shows (set from the `title` / `description` slots, as Carbon). */ withHeader: boolean; /** Whether the search leaves a row out: true hides it (Carbon `filterRows`; default: its text doesn't contain the search). */ filterRows: (rowText: string, searchString: string) => boolean; /** A resize handle on every header (or `resizable` on single headers). */ resizable: boolean; /** Rows per page: above 0 a `` pages the rows the sort and search leave. */ pageSize: number; /** The page shown (from 1). */ page: number; /** The page sizes the pagination offers (comma-separated). */ pageSizes: string; /** Skeleton rows instead of the body while the data loads (the table is `aria-busy`). */ loading: boolean; /** How many skeleton rows `loading` shows (default: the rows shown now, else the page size, else 5). */ loadingRows: number; /** Keeps the header in view while the body scrolls inside a box (Carbon React `stickyHeader`; `--ui-table-max-height`, default 300px). */ stickyHeader: boolean; /** What the live region says ("Loading data" when `loading` turns on). */ private announcement; /** The columns are wider than the box: it scrolls sideways (and takes focus, WCAG 2.1.1). */ private scrollable; private resizeObserver?; /** The hidden columns when the table first got its headers (what Reset restores). */ private initialHidden; /** The batch bar's "Select all (N)" is the table's own (paging), not the author's (server paging). */ private ownsTotal; private readonly localize; private readonly grid; /** Each row's place in the order the rows came in (what none restores). */ private readonly order; private nextIndex; /** A header with a `sort-direction` in the markup has sorted the first rows. */ private initiallySorted; /** * Compares two cells' sort values (Carbon `customSortRow`) for ascending order: numbers by value, text * with `collator`. Replace it on the element to sort another way. */ customSortRow(lhs: string, rhs: string, collator: Intl.Collator): number; connectedCallback(): void; protected firstUpdated(): void; private observeSize; disconnectedCallback(): void; private get listeners(); private get body(); private get headerCells(); private get rows(); private get headerRow(); private get batchActions(); private get toolbarContent(); /** The rows select-all and the arrow keys reach: shown (search, page) and not disabled. */ private get selectableRows(); /** The column headers, in order (the column settings list them). */ get columns(): UiTableHeaderCell[]; /** The keys of the hidden columns. */ get hiddenColumns(): string[]; /** Whether `column` can't be hidden or shown now: not hideable, or the last one shown. */ isColumnLocked(column: string): boolean; /** The headers as the core column helpers see them. */ private get columnModel(); /** Width of the horizontal scroll box (a resize stops a column there). */ get contentWidth(): number; /** The chosen rows. */ get selectedRows(): UiTableRow[]; private get sortedHeader(); protected willUpdate(changed: Map): void; protected updated(changed: Map): void; /** New head, body or toolbar: pass the table's settings down. */ private readonly onSlotChange; /** A title or description came or went: the header block shows while there is one (Carbon `withHeader`). */ private readonly onHeaderSlotChange; /** Selection and expand settings onto the rows, the expanded rows' span, the toolbar's size. */ private syncRows; /** The columns' hidden and pinned states onto every row's cells, the expanded rows' span, the pin offsets. */ private syncColumns; /** A pinned first column sits after the chevron and checkbox columns, which stick before it. */ private measurePins; /** Shows or hides a column (and its cells); false when it can't change (not hideable, or the last one shown). */ setColumnHidden(column: string, hidden: boolean): boolean; /** Columns were shown or hidden since the markup (Reset has something to do). */ get columnsChanged(): boolean; /** Back to the columns hidden in the markup. */ resetColumns(): void; private afterColumnsChange; /** * The first resize freezes the automatic layout: every shown column keeps its width, a filler cell takes the rest * of the row (none in a static-width table, which ends at its columns). */ freezeColumns(): void; /** The widths given or resized, by column. */ get columnWidths(): Record; /** Built-in paging: the rows the search shows, one page of them on screen; the pagination and select-all follow. */ private syncPaging; /** With paging, "Select all (N)" offers every row the search shows (unless the author set the count). */ private syncTotal; private readonly onPageChange; /** The table's own "Select all (N)": choose every row the search shows, on every page. */ private readonly onSelectAllPages; private renderPagination; /** The header's select-all, the radios' Tab stop and the batch actions follow the chosen rows. */ private syncSelection; /** After every listener ran (a canceled event leaves things to whoever canceled it). */ private afterListeners; private readonly onRowSelection; /** Choose or release every row the search shows (disabled rows keep their state). */ private selectAll; private readonly onSelectAll; /** Cancel releases every row; focus goes to select-all, as out of a closing dialog (the bar it was in goes inert). */ private readonly onCancel; /** Arrow keys on a radio: the next (or previous) reachable row is chosen and focused, wrapping around. */ private readonly onRadioMove; /** The header's chevron opens or closes every row; a row's keeps the header's in step. */ private readonly onExpando; /** The search text (the toolbar search's). */ private searchValue; /** The toolbar search changed: leave out the rows whose text (or their expanded row's) doesn't contain it. */ private readonly onSearch; /** A row's text for the search: its shown cells (hidden columns don't count). */ private rowText; /** Marks the rows the search leaves out; returns the rest. */ private applySearch; private syncBody; private syncHeaders; /** Rows came, went or moved: while nothing is sorted, their order is the one none restores. */ private readonly onContentChange; private indexNewRows; private readonly onSort; /** * Each body row with what follows it until the next row (an expanded row), and the text and comment nodes before * it (whitespace, a framework's markers): they move with the row. Left behind they would pile up before the rows, * and Chrome moves rows past such a pile slowly (3,000 rows: 90ms a sort instead of 12). */ private rowGroups; /** The row a group of nodes is for. */ private rowOf; private sortRows; /** * Puts the body's children in `children` order. The body leaves the page meanwhile: WebKit reassigns a * slot's nodes on every move, which makes moving rows inside it quadratic (1,000 rows: seconds). */ private reorder; /** The rows CSV takes: those the search shows (every page, in their order), the chosen ones, or all. */ csvRows(scope?: TableCsvScope): UiTableRow[]; /** The columns shown and the rows of `scope` as CSV (a cell writes its `csv-value`, else its text). */ toCsv({ scope }?: { scope?: TableCsvScope; }): string; /** Downloads `toCsv({ scope })` as `fileName` (default: the title, else "table"; `.csv` is added). */ downloadCsv({ scope, fileName }?: { scope?: TableCsvScope; fileName?: string; }): void; /** The file name a CSV download takes by default: the title's text. */ get csvFileName(): string; /** Skeleton rows in the table's columns while `loading`. */ private renderLoading; private renderLoadingRow; /** No rows: the `empty` slot, or `no-results` while the search leaves none. */ private renderEmpty; private renderSlot; /** * Focuses the table's first stop: the scroll box when it scrolls, else select-all, a sort button, the grid's * Tab stop, or the first row's checkbox, radio or chevron. */ focus(options?: FocusOptions): void; /** The scroll box's name: the table's `aria-label`, else its title. */ private get regionLabel(); render(): import("lit-html").TemplateResult<1>; } export interface UiTableEventMap extends HTMLElementEventMap { /** From a header (it bubbles): listen on the table to sort the data yourself. */ 'ui-table-header-cell-sort': CustomEvent; 'ui-table-sorted': CustomEvent; /** From a row (it bubbles), cancelable. */ 'ui-table-row-change-selection': CustomEvent; /** From the header row (it bubbles), cancelable. */ 'ui-table-change-selection-all': CustomEvent; 'ui-table-row-selected': CustomEvent; 'ui-table-row-all-selected': CustomEvent; /** From a row (it bubbles), cancelable. */ 'ui-table-row-expando-beingtoggled': CustomEvent; 'ui-table-row-expando-toggled': CustomEvent; 'ui-table-filtered': CustomEvent; 'ui-table-page-change': CustomEvent; 'ui-table-columns-change': CustomEvent; /** From a cell (it bubbles), cancelable. */ 'ui-table-cell-edit': CustomEvent; /** From the `` (it bubbles), cancelable. */ 'ui-table-csv-export': CustomEvent; /** From a header (it bubbles). */ 'ui-table-column-resize': CustomEvent; } /** Typed listeners for UiTable's events (declaration merging with the class). */ export interface UiTable { addEventListener(type: K, listener: (this: UiTable, event: UiTableEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: UiTable, event: UiTableEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } declare global { interface HTMLElementTagNameMap { 'ui-table': UiTable; } }