/* * Copyright (c) 2025, Salesforce, Inc. * All rights reserved. * For full license text, see the LICENSE.txt file */ /** * The `lightning/datatable` component displays tabular data where each column can be displayed based on the data type. * It provides features like sorting, row selection, inline editing, infinite scrolling, and more. * @see {@link https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentation |Lightning Datatable Documentation} */ declare module "lightning/datatable" { import { LightningElement } from "lwc"; /** * Type attributes for action columns. */ interface ActionTypeAttributes { rowActions: Array<{ label: string; name: string; disabled?: boolean; iconName?: string; }>; menuAlignment?: | "right" | "left" | "auto" | "center" | "bottom-left" | "bottom-center" | "bottom-right"; } /** * Type attributes for button columns. */ interface ButtonTypeAttributes { disabled?: boolean; iconName?: string; iconPosition?: "left" | "right"; label?: string; name?: string; title?: string; variant?: | "base" | "neutral" | "brand" | "destructive" | "inverse" | "success"; } /** * Type attributes for button-icon columns. */ interface ButtonIconTypeAttributes { alternativeText?: string; class?: string; disabled?: boolean; iconClass?: string; iconName?: string; name?: string; title?: string; variant?: | "bare" | "container" | "border" | "border-filled" | "bare-inverse" | "border-inverse"; } /** * Type attributes for currency columns. */ interface CurrencyTypeAttributes { currencyCode?: string; currencyDisplayAs?: "symbol" | "code" | "name"; minimumIntegerDigits?: number; minimumFractionDigits?: number; maximumFractionDigits?: number; minimumSignificantDigits?: number; maximumSignificantDigits?: number; step?: number; } /** * Type attributes for date columns. */ interface DateTypeAttributes { day?: "numeric" | "2-digit"; era?: "narrow" | "short" | "long"; hour?: "numeric" | "2-digit"; hour12?: boolean; minute?: "numeric" | "2-digit"; month?: "numeric" | "2-digit" | "narrow" | "short" | "long"; second?: "numeric" | "2-digit"; timeZone?: string; timeZoneName?: "short" | "long"; weekday?: "narrow" | "short" | "long"; year?: "numeric" | "2-digit"; } /** * Type attributes for date-local columns. */ interface DateLocalTypeAttributes { day?: "numeric" | "2-digit"; month?: "numeric" | "2-digit" | "narrow" | "short" | "long"; year?: "numeric" | "2-digit"; } /** * Type attributes for location columns. */ interface LocationTypeAttributes { latitude: number; longitude: number; } /** * Type attributes for number columns. */ interface NumberTypeAttributes { minimumIntegerDigits?: number; minimumFractionDigits?: number; maximumFractionDigits?: number; minimumSignificantDigits?: number; maximumSignificantDigits?: number; } /** * Type attributes for percent columns. */ interface PercentTypeAttributes { minimumIntegerDigits?: number; minimumFractionDigits?: number; maximumFractionDigits?: number; minimumSignificantDigits?: number; maximumSignificantDigits?: number; step?: number; } /** * Type attributes for text columns. */ interface TextTypeAttributes { linkify?: boolean; } /** * Type attributes for URL columns. */ interface UrlTypeAttributes { label?: string; target?: "_blank" | "_self" | "_parent" | "_top"; tooltip?: string; } /** * Union type of all possible type attributes for different column types. */ type TypeAttributes = | ActionTypeAttributes | ButtonTypeAttributes | ButtonIconTypeAttributes | CurrencyTypeAttributes | DateTypeAttributes | DateLocalTypeAttributes | LocationTypeAttributes | NumberTypeAttributes | PercentTypeAttributes | TextTypeAttributes | UrlTypeAttributes; /** * Cell attributes for customizing cell appearance and behavior. */ interface CellAttributes { /** * Alignment of the cell content. Valid values are 'left', 'right', 'center' */ alignment?: "left" | "right" | "center"; /** * CSS classes to apply to the cell */ class?: string; /** * Icon name to display in the cell */ iconName?: string | { fieldName: string }; /** * Icon label to display next to the icon */ iconLabel?: string | { fieldName: string }; /** * Position of the icon relative to the data. Valid values are 'left' and 'right' */ iconPosition?: "left" | "right"; /** * Alternative text for the icon */ iconAlternativeText?: string; } /** * Column definition for lightning-datatable. */ interface ColumnDefinition { /** * Required. The text label displayed in the column header. If hideLabel and iconName are set, * the label is used as hover text for the icon and as the value of aria-label. */ label: string; /** * Required. The name that binds the columns attributes to the associated data. * Each columns attribute must correspond to an item in the data array. */ fieldName: string; /** * Required. The data type to be used for data formatting. * Valid types: 'action', 'boolean', 'button', 'button-icon', 'currency', 'date', * 'date-local', 'email', 'location', 'number', 'percent', 'phone', 'text', 'url' */ type: string; /** * Appends a dropdown menu of actions to a column. You must pass in a list of label-name pairs. */ actions?: object; /** * Provides additional customization using alignment and class properties, * in addition to icon* properties such as for appending an icon to the output. */ cellAttributes?: CellAttributes; /** * Specifies whether a column supports inline editing. The default is false. */ editable?: boolean; /** * Specifies the width of a column in pixels and makes the column non-resizable. * If both fixedWidth and initialWidth values are provided, initialWidth is ignored. */ fixedWidth?: number; /** * Specifies whether to hide the default header actions on a column. The default is false. */ hideDefaultActions?: boolean; /** * Specifies whether to hide the label on a column. The default is false. */ hideLabel?: boolean; /** * The Lightning Design System name of the icon. Names are written in the format standard:opportunity. * The icon is appended to the left of the header label. * If hideLabel is provided, only the icon displays in the column header. */ iconName?: string; /** * The URI for a custom icon. The icon is appended to the left of the header label. * If hideLabel is provided, only the icon displays in the column header. * If there's an error loading the URI, iconName is used as a fallback. */ imgSrc?: string; /** * The width of the column when it's initialized, which must be within the min-column-width * and max-column-width values, or within 50px and 1000px if they are not provided. */ initialWidth?: number; /** * Specifies whether the column can be sorted. The default is false. */ sortable?: boolean; /** * Provides custom formatting with component attributes for the data type. * For example, currency-code for the currency type. * The supported attributes depend on the column type. */ typeAttributes?: TypeAttributes; /** * Specifies whether text in a column is wrapped when the table renders. * Wrapped text vertically expands a row to reveal its full content. * Use with wrap-text-max-lines to display a number of lines before hiding the rest. */ wrapText?: boolean; /** * Unique ID for a column when using the same field name for multiple columns. * Use columnKey instead of fieldName to give a column a unique identifier. */ columnKey?: string; /** * Displays a lock icon on read-only fields to indicate they're not editable. * Must be used with editable: false. */ displayReadOnlyIcon?: boolean; } /** * Row data structure for lightning-datatable. */ interface RowData { /** * Unique identifier for the row. This should match the keyField property of the datatable. */ id?: string | number; /** * Row data can contain various field types that correspond to column types: * - For 'action' columns: typically not stored in row data * - For 'boolean' columns: boolean values * - For 'button' columns: typically not stored in row data * - For 'button-icon' columns: typically not stored in row data * - For 'currency' columns: number values * - For 'date' columns: Date object, ISO string, or timestamp * - For 'date-local' columns: Date object, ISO string, or timestamp (browser local time zone) * - For 'email' columns: string email addresses * - For 'location' columns: object with latitude and longitude properties * - For 'number' columns: number values * - For 'percent' columns: number values (e.g., 0.25 for 25%) * - For 'phone' columns: string phone numbers * - For 'text' columns: string values (default type) * - For 'url' columns: string URLs */ [key: string]: | string | number | boolean | Date | null | undefined | { latitude?: number; longitude?: number; }; } /** * Error structure for displaying validation errors in the datatable. */ interface RowError { /** * Title for the error tooltip displayed in the row number column */ title?: string; /** * Array of error messages to display in the tooltip */ messages?: string[]; /** * Fields that triggered errors. Can be specified as: * - A simple array of field names (order must match messages array) * - An object with field names as keys and custom error messages as values */ fieldNames?: string[] | { [fieldName: string]: string }; } /** * Table-level error structure for lightning-datatable. */ interface TableError { /** * Title for the error tooltip displayed at the bottom of the table */ title?: string; /** * Array of error messages to display in the table-level error tooltip */ messages?: string[]; } /** * Error configuration for lightning-datatable. */ interface Errors { /** * Row-level errors. Keys are the datatable's key-field values. * Each row can have its own error configuration. */ rows?: { [keyFieldValue: string]: RowError }; /** * Table-level errors displayed at the bottom of the table. * Requires the bottom bar to be visible (suppress-bottom-bar must not be set). */ table?: TableError; } /** * A table that displays rows and columns of data. */ export default class LightningDatatable extends LightningElement { /** * Public property for passing `aria-label` down to the child table element. */ ariaLabel: string | null; /** * Public property for passing `aria-labelledby` down to the child table element. */ ariaLabelledBy: string | null; /** * Specifies the ID or space-separated list of IDs that describes the current element. */ ariaDescribedBy: string | null; /** * Specifies how column widths are calculated. Set to 'fixed' for columns with equal widths. * Set to 'auto' for column widths that are based on the width of the column content and the table width. The default is 'fixed'. */ columnWidthsMode: "fixed" | "auto"; /** * Array of the columns object that's used to define the data types. * Required properties include 'label', 'fieldName', and 'type'. The default type is 'text'. * See the Documentation tab for more information. */ columns: ColumnDefinition[]; /** * The array of data to be displayed. */ data: RowData[]; /** * Specifies the default sorting direction on an unsorted column. * Valid options include 'asc' and 'desc'. * The default is 'asc' for sorting in ascending order. */ defaultSortDirection: "asc" | "desc"; /** * The current values per row that are provided during inline edit. * Array of objects containing the edited field values, where each object * must include the key-field value to identify the row. */ draftValues: Array>; /** * If present, you can load a subset of data and then display more * when users scroll to the end of the table. * Use with the onloadmore event handler to retrieve more data. */ enableInfiniteLoading: boolean; /** * Specifies an object containing information about cell level, row level, and table level errors. * When it's set, error messages are displayed on the table accordingly. */ errors: Errors; /** * If present, the checkbox or radio button column for row selection is hidden. */ hideCheckboxColumn: boolean; /** * If present, the actions menu is displayed to enable users to do advanced sorting. */ showActionsMenu: boolean; /** * If present, the table header is hidden. */ hideTableHeader: boolean; /** * Specifies how the table header is wrapped. Set to 'all' to wrap all column headers. * Set to 'none' to clip all column headers. Set to 'by-column' to wrap/clip column headers * based on the wrap/clip setting for that individual column. The default is 'none'. */ wrapTableHeader: "all" | "by-column" | "none"; /** * If present, a spinner is shown to indicate that more data is loading. */ isLoading: boolean; /** * Required for better performance. Associates each row with a unique ID. * key-field is case sensitive and must match the value you provide in the data array. */ keyField: string | undefined; /** * Determines when to trigger infinite loading based on * how many pixels the table's scroll position is from the bottom of the table. * The default is 20. */ loadMoreOffset: number; /** * The maximum width for all columns. * The default is 1000px. */ maxColumnWidth: number; /** * The maximum number of rows that can be selected. Value should be a positive integer * Checkboxes are used for selection by default, * and radio buttons are used when maxRowSelection is 1 unless overridden using * the singleRowSelectionMode property. */ maxRowSelection: number | undefined; /** * Specifies whether to render checkboxes instead of radio buttons. * Use with max-row-selection. * When max-row-selection is 1, radio buttons are used for selection by default. * Valid values are 'radio' and 'checkbox'. The default value is 'radio'. */ singleRowSelectionMode: "radio" | "checkbox" | undefined; /** * The minimum width for all columns. * The default is 50px. */ minColumnWidth: number; /** * Opts-in to a role-based table. * Valid options are 'role-based' and 'default'. * 'role-based' renders
. * 'default' renders . * Reserved for internal use. */ renderMode: "role-based" | "default"; /** * If present, column resizing is disabled. */ resizeColumnDisabled: boolean; /** * The width to resize the column when a user presses left or right arrow. * The default is 10px. */ resizeStep: number; /** * Determines where to start counting the row number. * The default is 0. */ rowNumberOffset: number; /** * Enables programmatic row selection with a list of key-field values. */ selectedRows: string[]; /** * If present, the row numbers are shown in the first column. */ showRowNumberColumn: boolean; /** * The column key or fieldName(s) that controls the sorting order. * Sort the data using the onsort event handler. */ sortedBy: string | string[] | undefined; /** * Specifies the sorting direction. * Sort the data using the onsort event handler. * Valid options include a single value of 'asc' or 'desc' or an array of such values. */ sortedDirection: string | string[] | undefined; /** * If present, the footer that displays the Save and Cancel buttons is hidden during inline editing. */ suppressBottomBar: boolean; /** * This value specifies the number of lines after which the * content will be cut off and hidden. It must be at least 1 or more. * The text in the last line is truncated and shown with an ellipsis. */ wrapTextMaxLines: number | undefined; /** * Focuses the current active cell in the datatable. */ focus(): void; /** * Returns data in each selected row. */ getSelectedRows(): RowData[]; /** * Opens the inline edit panel for the datatable's currently active cell. If the active cell is not * editable, then the panel is instead opened for the first editable cell in the table. Given two * distinct cells, C_x and C_y, C_x is considered "first" in the cell ordering if the following condition * evaluates to true: * * (C_x.rowIndex < C_y.rowIndex) || (C_x.rowIndex === C_y.rowIndex && C_x.columnIndex < C_y.columnIndex) * * If there is no data in the table or there are no editable cells in the table then calling this function * results in a no-op. */ openInlineEdit(): void; /** * Scrolls to the top of the datatable. */ scrollToTop(): void; } }