Компоненты PrimeNG
Table
Документация

Документация таблиц

PrimeNG/Table (opens in a new tab)

Таблица отображает данные в табличном формате.

С чего начать

Подключите модуль

import { TableModule } from 'primeng-lts/table';

Шаблоны

NameParametersDescription
caption-Caption content of the table.
header$implicit: ColumnsContent of the thead element.
headergrouped$implicit: ColumnsContent of the thead element.
body$implicit: Data of the row<br>rowIndex: Index of the row<br>columns: Columns collection<br>expanded: Whether the row is expanded<br>rowgroup: Wheter the row is rowgroup<br>rowspan: Row span of the rowgroupContent of the tbody element.
footer$implicit: ColumnsContent of the tfoot element.
footergrouped$implicit: ColumnsContent of the tfoot element.
summary-Summary section to display below the table.
rowexpansion$implicit: Data of the row<br>rowIndex: Index of the row<br>columns: Columns collection<br>Content of an extended row.
frozenrows$implicit: Data of the row<br>rowIndex: Index of the row<br>columns: Columns collection<br>Content of the tbody element to display frozen rows.
frozenbody$implicit: Data of the row<br>rowIndex: Index of the row<br>columns: Columns collection<br>Content of the tbody element in frozen side.
frozenrowexpansion$implicit: Data of the row<br>rowIndex: Index of the row<br>columns: Columns collection<br>Content of an extended row in frozen side.
groupheader$implicit: Data of the row<br>rowIndex: Index of the row<br>columns: Columns collection<br>Header of the grouped rows.
groupfooter$implicit: Data of the row<br>rowIndex: Index of the row<br>columns: Columns collection<br>Footer of the grouped rows.
emptymessage$implicit: Columns<br>frozen: Whether the body belongs to the frozen part of the table.Content to display when there is no value to display.
paginatorleftstate: $implicit state.page: Current page<br>state.pageCount: Total page count<br>state.rows: Rows per page<br>state.first: Index of the first records<br>state.totalRecords: Number of total records<br>Custom content for the left section of the paginator.
paginatorrightstate: $implicit state.page: Current page<br>state.pageCount: Total page count<br>state.rows: Rows per page<br>state.first: Index of the first records<br>state.totalRecords: Number of total records<br>Custom content for the right section of the paginator.
loadingbodycolumns: Columns collection<br>Content of the tbody element to show when data is being loaded in virtual scroll mode.

Свойства ColumnFilter

NameTypeDefaultDescription
fieldstringnullName of the property of the data to filter.
typestringtextData type to display a suitable filter and matchers.
displaystringrowDisplay mode, valid values are "row" for a separate row and "menu" for filter menu.
showMenubooleantrueWhether to show the overlay menu.
matchModestringnullDefault match mode.
operatorstringandDefault operator, valid values are "and" and "or".
showOperatorbooleantrueSpecifies if the operator selection is displayed.
showClearButtonbooleantrueWhether to display the clear button.
showApplyButtonbooleantrueWhether to display the apply button.
showMatchModesbooleantrueWhether to display the match modes dropdown.
showAddButtonbooleantrueWhether to display the add a rule button.
hideOnClearbooleanfalseWhether to hide the overlay on clear.
placeholderstringnullAdvisory information to display on input.
matchModeOptionsSelectItem[]nullMatch mode options to override the global setting.
maxConstraintsnumber2Number of maximum constraints.
minFractionDigitsnumbernullThe minimum number of fraction digits to use for "numeric" type. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the <a href="https://www.currency-iso.org/en/home/tables/table-a1.html"&gt;ISO (opens in a new tab) 4217 currency code list</a> (2 if the list doesn't provide that information).
maxFractionDigitsnumbernullThe maximum number of fraction digits to use for "numeric" type. Possible values are from 0 to 20; the default for plain number formatting is the larger of minimumFractionDigits and 3; the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the <a href="https://www.currency-iso.org/en/home/tables/table-a1.html"&gt;ISO (opens in a new tab) 4217 currency code list</a> (2 if the list doesn't provide that information).
prefixstringnullText to display before the value for "numeric" type.
suffixstringdecimalText to display after the value for "numeric" type.
localestringnullLocale to be used in formatting for "numeric" type.
localeMatcherstringbest fitThe locale matching algorithm for "numeric" type. Possible values are "lookup" and "best fit"; the default is "best fit". See <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation"&gt;Locale (opens in a new tab) Negotation</a> for details.
currencystringnullThe currency to use in currency formatting for "numeric" type. Possible values are the <a href="https://www.currency-iso.org/en/home/tables/table-a1.html"&gt;ISO (opens in a new tab) 4217 currency codes</a>, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB. There is no default value; if the style is "currency", the currency property must be provided.
currencyDisplaystringsymbolHow to display the currency in currency formatting for "numeric" type. Possible values are "symbol" to use a localized currency symbol such as €, ü"code" to use the ISO currency code, "name" to use a localized currency name such as "dollar"; the default is "symbol".
useGroupingbooleantrueWhether to use grouping separators for "numeric" type, such as thousands separators or thousand/lakh/crore separators.

Шаблоны ColumnFilter

NameParameters
header-
filter$implicit: filter value<br>filterCallback: Callback function of the filter
footer-

Свойства TableCheckbox

NameTypeDefaultDescription
valueanynullRow data value of the component.
indexnumbernullIndex of the row.
disabledbooleanfalseWhether the component is disabled.
inputIdstringnullIdentifier of the checkbox.
namestringnullName of the checkbox.
requiredbooleanfalseWhen present, it specifies that checkbox must be checked before submitting the form.
ariaLabelstringnullDefines a string that labels the checkbox for accessibility.

Свойства TableHeaderCheckbox

NameTypeDefaultDescription
disabledbooleanfalseWhether the component is disabled.
inputIdstringnullIdentifier of the checkbox.
namestringnullName of the checkbox.
ariaLabelstringnullDefines a string that labels the checkbox for accessibility.

Свойства TableRadioButton

NameTypeDefaultDescription
valueanynullRow data value of the component.
indexnumbernullIndex of the row.
disabledbooleanfalseWhether the component is disabled.
inputIdstringnullIdentifier of the radiobutton.
namestringnullName of the radiobutton.
ariaLabelstringnullDefines a string that labels the element for accessibility.

Свойства

NameTypeDefaultDescription
valuearraynullAn array of objects to display.
columnsarraynullAn array of objects to represent dynamic columns.
frozenColumnsarraynullAn array of objects to represent dynamic columns that are frozen.
frozenValuearraynullAn array of objects to display as frozen.
responsiveLayoutstringstackDefines the responsive mode, valid options are "stack" and "scroll".
breakpointstring960pxThe breakpoint to define the maximum width boundary when using stack responsive layout.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
tableStyleanynullInline style of the table.
tableStyleClassstringnullStyle class of the table.
paginatorbooleanfalseWhen specified as true, enables the pagination.
rowsnumbernullNumber of rows to display per page.
firstnumber0Index of the first row to be displayed.
totalRecordsnumbernullNumber of total records, defaults to length of value when not defined.
pageLinksnumbernullNumber of page links to display in paginator.
rowsPerPageOptionsarraynullArray of integer/object values to display inside rows per page dropdown of paginator
alwaysShowPaginatorbooleantrueWhether to show it even there is only one page.
showFirstLastIconbooleantrueWhen enabled, icons are displayed on paginator to go first and last page.
paginatorPositionstringbottomPosition of the paginator, options are "top", "bottom" or "both".
currentPageReportTemplatestring(currentPage of totalPages)Template of the current page report element. Available placeholders are currentPage,totalPages,rows,first,last and totalRecords
showCurrentPageReportbooleanfalseWhether to display current page report.
showJumpToPageDropdownbooleanfalseWhether to display a dropdown to navigate to any page.
showJumpToPageInputbooleanfalseWhether to display a input to navigate to any page.
showPageLinksbooleantrueWhether to show page links.
sortModestringsingleDefines whether sorting works on single column or on multiple columns.
sortFieldstringnullName of the field to sort data by default.
sortOrdernumber1Order to sort when default sorting is enabled.
multiSortMetaarraynullAn array of SortMeta objects to sort the data by default in multiple sort mode.
rowGroupModestringnullType of the row grouping, valid values are "subheader" and "rowspan".
groupRowsBystring|arraynullOne or more field names to use in row grouping.
groupRowsByOrdernumber1Order to sort when default row grouping is enabled.
defaultSortOrdernumber1Sort order to use when an unsorted column gets sorted by user interaction.
customSortbooleanfalseWhether to use the default sorting or a custom one using sortFunction.
showInitialSortBadgebooleantrueWhether to use the initial sort badge or not.
sortFunctionfunctionnullA function to implement custom sorting, refer to sorting section for details.
selectionModestringnullSpecifies the selection mode, valid values are "single" and "multiple".
selectionanynullSelected row in single mode or an array of values in multiple mode.
contextMenuSelectionanynullSelected row with a context menu.
contextMenuSelectionModestringseparateDefines the behavior of context menu selection, in "separate" mode context menu updates contextMenuSelection property whereas in joint mode selection property is used instead so that when row selection is enabled, both row selection and context menu selection use the same property.
dataKeystringnullA property to uniquely identify a record in data.
metaKeySelectionbooleantrueDefines whether metaKey should be considered for the selection. On touch enabled devices, metaKeySelection is turned off automatically.
rowTrackByFunctionnullFunction to optimize the dom operations by delegating to ngForTrackBy, default algoritm checks for object identity.
lazybooleanfalseDefines if data is loaded and interacted with in lazy manner.
lazyLoadOnInitbooleantrueWhether to call lazy loading on initialization.
compareSelectionBystringdeepEqualsAlgorithm to define if a row is selected, valid values are "equals" that compares by reference and "deepEquals" that compares all fields.
csvSeparatorstring,Character to use as the csv separator.
exportFilenamestringdownloadName of the exported file.
filtersarraynullAn array of FilterMetadata objects to provide external filters.
filterDelaynumber300Delay in milliseconds before filtering the data.
globalFilterFieldsarraynullAn array of fields as string to use in global filtering.
filterLocalestringundefinedLocale to use in filtering. The default locale is the host environment's current locale.
expandedRowKeys[s: string]: boolean;nullMap instance to keep the expanded rows where key of the map is the data key of the row.
rowExpandModestringmultipleWhether multiple rows can be expanded at any time. Valid values are "multiple" and "single".
scrollablebooleanfalseWhen specifies, enables horizontal and/or vertical scrolling.
scrollDirectionstringverticalOrientation of the scrolling, options are "vertical", "horizontal" and "both".
scrollHeightstringnullHeight of the scroll viewport in fixed pixels or the "flex" keyword for a dynamic size.
virtualScrollbooleanfalseWhether the data should be loaded on demand during scroll.
virtualScrollDelaynumber250Threshold in milliseconds to delay lazy loading during scrolling.
virtualRowHeightnumber28Height of a row to use in calculations of virtual scrolling.
contextMenuContextMenunullLocal ng-template varilable of a ContextMenu.
resizableColumnsbooleanfalseWhen enabled, columns can be resized using drag and drop.
columnResizeModestringfitDefines whether the overall table width should change on column resize, valid values are "fit" and "expand".
reorderableColumnsbooleanfalseWhen enabled, columns can be reordered using drag and drop.
loadingbooleanfalseDisplays a loader to indicate data load is in progress.
loadingIconstringpi-circle-o-notchThe icon to show while indicating data load is in progress.
showLoaderbooleantrueWhether to show the loading mask when loading property is true.
rowHoverbooleanfalseAdds hover effect to rows without the need for selectionMode. Note that tr elements that can be hovered need to have "p-selectable-row" class for rowHover to work.
paginatorDropdownAppendToanynullTarget element to attach the paginator dropdown overlay, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name).
paginatorDropdownScrollHeightstring200pxPaginator dropdown height of the viewport in pixels, a scrollbar is defined if height of list exceeds this value.
autoLayoutbooleanfalseWhether the cell widths scale according to their content or not.
resetPageOnSortbooleantrueWhen true, resets paginator to first page after sorting. Available only when sortMode is set to single.
exportFunctionfunctionnullA function to implement custom export. Need to return string value.<br>event.data: Field data.<br>event.field: Column field.
stateKeystringnullUnique identifier of a stateful table to use in state storage.
stateStoragestringsessionDefines where a stateful table keeps its state, valid values are "session" for sessionStorage and "local" for localStorage.
editModestringcellDefines the editing mode, valid values are "cell" and "row".
editingRowKeys[s: string]: boolean;nullMap instance to keep the rows being edited where key of the map is the data key of the row.
minBufferPxnumbernullMinimum amount of content buffer (in pixels) that the viewport must render.
maxBufferPxnumbernullConfigures how much buffer space to render back up to when it detects that more buffer is required.

События

NameParametersDescription
onRowSelectevent.originalEvent: Browser event<br>event.data: Selected row data or an array if a range is selected with shift key<br>event.type: Type of selection, valid values are "row", "radiobutton" and "checkbox"<br>event.index: Index of the rowCallback to invoke when a row is selected.
onRowUnselectevent.originalEvent: Browser event<br>event.data: Unselected data<br>event.type: Type of unselection, valid values are "row" and "checkbox"<br>event.index: Index of the rowCallback to invoke when a row is unselected.
onPageevent.first: Index of first record in page<br>event.rows: Number of rows on the pageCallback to invoke when pagination occurs.
onSortevent.field: Field name of the sorted column<br>event.order: Sort order as 1 or -1<br>event.multisortmeta: Sort metadata in multi sort mode. See multiple sorting section for the structure of this object.Callback to invoke when a column gets sorted.
onFilterevent.filters: Filters object having a field as the property key and an object with value, matchMode as the property value.<br>event.filteredValue: Filtered data after running the filtering.Callback to invoke when data is filtered.
onLazyLoadevent.first = First row offset<br>event.rows = Number of rows per page<br>event.sortField = Field name to sort with<br>event.sortOrder = Sort order as number, 1 for asc and -1 for dec<br>event.multiSortMeta: An array of SortMeta objects used in multiple columns sorting. Each SortMeta has field and order properties.<br>event.filters: FilterMetadata object having field as key and filter value, filter matchMode as value<br>event.globalFilter: Value of the global filter if availableCallback to invoke when paging, sorting or filtering happens in lazy mode.
onRowExpandevent.originalEvent: Browser event<br>data: Row data to expand.Callback to invoke when a row is expanded.
onRowCollapseevent.originalEvent: Browser event<br>data: Row data to collapse.Callback to invoke when a row is collapsed.
onContextMenuSelectevent.originalEvent: Browser event<br>event.data: Selected dataCallback to invoke when a row is selected with right click.
onColResizeevent.element: Resized column header<br>event.delta: Change of width in number of pixelsCallback to invoke when a column is resized.
onColReorderevent.dragIndex: Index of the dragged column<br>event.dropIndex: Index of the dropped column<br>event.columns: Columns array after reorderCallback to invoke when a column is reordered.
onRowReorderevent.dragIndex: Index of the dragged row<br>event.dropIndex: Index of the drop locationCallback to invoke when a row is reordered.
onEditInitevent.field: Column object of the cell<br>event.data: Row dataCallback to invoke when a cell switches to edit mode.
onEditCompleteevent.field: Column object of the cell<br>event.data: Row data<br>event.originalEvent: Browser eventCallback to invoke when cell edit is completed.
onEditCancelevent.field: Column object of the cell<br>event.data: Row data<br>event.originalEvent: Browser eventCallback to invoke when cell edit is cancelled with escape key.
onHeaderCheckboxToggleevent.originalEvent: Browser event<br>event.checked: State of the header checkboxCallback to invoke when state of header checkbox changes.
onStateSavestate: Table stateCallback to invoke table state is saved.
onStateRestorestate: Table stateCallback to invoke table state is restored.

Методы

NameParametersDescription
reset-Resets sort, filter and paginator state.
clearState-Clears table state.
exportCSVconfig?.selectionOnly: Exports only the selection.Exports the data in csv format.
resetScrollTop-Resets the scrollable table scroll position to the beginning.
scrollToVirtualIndexindexScrolls to the row with the given index when virtual scrolling is enabled.
scrollTooptions.left: Specifies the number of pixels along the X axis<br>options.top: Specifies the number of pixels along the Y axis<br>options.behavior: Specifies whether the scrolling should animate smoothly (smooth), or happen instantly in a single jump (auto).Scrolls to a position of a scrollable table viewport.

Стилизация

NameElement
p-datatableContainer element.
p-datatable-headerHeader section.
p-datatable-footerFooter section.
p-sortable-columnSortable column header.
p-editable-columnEditable column cell.
p-datatable-theadThead element of header columns.
p-datatable-tbodyTbody element of body rows.
p-datatable-tfootTfoot element of footer columns.
p-datatable-scrollableContainer element when scrolling is enabled.
p-datatable-scrollable-frozenContainer element of a frozen view.
p-datatable-scrollable-headerContainer of header in a scrollable table.
p-datatable-scrollable-bodyContainer of body in a scrollable table.
p-datatable-scrollable-footerContainer of footer in a scrollable table.
p-datatable-resizableContainer element when column resizing is enabled.
p-datatable-resizable-fitContainer element when column resizing is enabled and set to fit mode.
p-column-resizer-helperVertical resizer indicator bar.
p-datatable-reorderablerow-handleHandle element of a reorderable row.
p-datatable-reorder-indicator-upUp indicator to display during column reordering.
p-datatable-reorder-indicator-upDown indicator to display during column reordering.
p-datatable-loading-overlayOverlay to display when table is loading.
p-datatable-loading-iconIcon to display when table is loading.