/* * Copyright (c) 2025, Salesforce, Inc. * All rights reserved. * For full license text, see the LICENSE.txt file */ /** * The `lightning/treeGrid` component displays hierarchical data in a table with expandable rows. * @see {@link https://developer.salesforce.com/docs/component-library/bundle/lightning-tree-grid/documentation | Lightning Tree Grid Documentation} */ declare module "lightning/treeGrid" { 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]: unknown; } /** * Tree row data structure extending the base RowData. * Each row can have a `_children` property containing nested rows. */ interface TreeRowData extends RowData { /** * Array of child rows that will be displayed when this row is expanded. * Must be properly formatted tree data. */ _children?: TreeRowData[]; } /** * Displays a hierarchical view of data in a table. */ export default class LightningTreeGrid extends LightningElement { /** * 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'. * @default 'fixed' */ columnWidthsMode: "fixed" | "auto"; /** * Specifies the default sorting direction on an unsorted column. * Valid options include 'asc' and 'desc'. * The default is 'asc' for sorting in ascending order. * @default 'asc' */ defaultSortDirection: "asc" | "desc"; /** * If present, the checkbox column for row selection is hidden. * @default false */ hideCheckboxColumn: boolean; /** * If present, a spinner is displayed to indicate that more data is being loaded. * @default false */ isLoading: boolean; /** * Required for better performance. Associates each row with a unique ID. */ keyField: string | undefined; /** * The maximum width for all columns. The default is 1000px. * @default 1000 */ maxColumnWidth: number; /** * The minimum width for all columns. The default is 50px. * @default 50 */ minColumnWidth: number; /** * If present, column resizing is disabled. * @default false */ resizeColumnDisabled: boolean; /** * Determines where to start counting the row number. The default is 0. * @default 0 */ rowNumberOffset: number; /** * If present, the row number column are shown in the first column. * @default false */ showRowNumberColumn: boolean; /** * The column key or fieldName(s) that controls the sorting order. * Sort the data using the onsort event handler. */ sortedBy: string | string[]; /** * 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[]; /** * 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[] | undefined; /** * The array of data to be displayed. */ data: TreeRowData[] | undefined; /** * The array of unique row IDs for rows that are expanded. */ expandedRows: Array; /** * Returns data in each selected row. * @returns {Array} An array of data in each selected row. */ getSelectedRows(): RowData[]; /** * Returns an array of rows that are expanded. * @returns {Array} The IDs for all rows that are marked as expanded */ getCurrentExpandedRows(): Array; /** * Expand all rows with children content */ expandAll(): void; /** * Collapse all rows */ collapseAll(): void; /** * Public property for passing `aria-label` down to the child table element. * @default '' */ ariaLabel: string; /** * Enables programmatic row selection with a list of key-field values. */ selectedRows: Array; } }