You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project extends 'angular material table' so that it can be used as a replacement for ngx-datatable in one of my projects. Unluckily ngx-datatable seems to be dead as it is still on angular v12 and an update to a more recent angular version is not in sight.
Mat-Datatable implements a table with virtual scrolling, sorting and filtering. Only a minimal set of the functionality of ngx-datatable is implemented.
To use this package in your project just follow these simple steps.
Prerequisites
The package can be used in Angular apps with Angular Material installed.
Installation
Install the package from npmjs:
npm install mat-datatable
Embed Mat-Datatable In Your Project
Use the component as a standalone Angular component. Some properties of mat-datatable must be configured in the component class (for example in app.component.ts):
The component is based on Angular Material and uses Google Fonts and the Google Material Icons font.
Both fonts are part of the project and not fetched via https.
Standalone Angular component for rendering a virtualized Material table. The component is generic so the row type can be provided with the template parameter.
Inputs
Name
Description
columnDefinitions: MatColumnDefinition<T>[]
Column definitions for the table. The order of the definitions does not need to match the visible column order.
displayedColumns: string[]
List of visible column IDs in the order they should be rendered.
rowSelectionMode: RowSelectionType
Controls row selection behaviour. Supported values are none, single and multi.
dataStoreProvider: DataStoreProvider<T>
Data source implementation for the table.
trackBy: TrackByFunction<T>
Optional row identity function.
withFooter: boolean
Enables the footer row.
Outputs
Name
Description
rowClick: EventEmitter<T>
Emitted when a row is clicked.
rowSelectionChange: EventEmitter<T[]>
Emitted when the current selection changes.
sortChange: EventEmitter<MatSortDefinition[]>
Emitted when the active sort definition changes.
Properties
Name
Description
activatedRow: T | undefined
Marks a row as active.
selectedRows: T[]
Contains the current selection.
sortDefinitions: MatSortDefinition[]
Gets or sets the current sort definition.
filterDefinitions: FieldFilterDefinition<T>[]
Gets or sets the active filter definition.
firstVisibleIndexChanged: Observable<number>
Emits the index of the first visible row.
totalRowsChanged: Observable<number>
Emits the total number of rows in the datastore.
filteredRowsChanged: Observable<number>
Emits the number of rows after filtering.
Methods
Name
Description
scrollToRow(row: T)
Scrolls the viewport so the given row becomes visible.
reloadTable()
Reloads the table from its datastore.
Interfaces
DataStoreProvider
Interface for a component that fetches data from the datastore while respecting sorting and filtering.
Methods
Name
Description
getPagedData(rowsRange, sorts, filters)
Fetches the requested page of data.
Parameters
rowsRange: RequestRowsRange
The range of rows to fetch.
sorts: FieldSortDefinition[]
The sort definitions to use.
filters: FieldFilterDefinition[]
The filter definitions to use.
Return value
Observable<Page>
Emitting fetched data from the datastore.
MatColumnDefinition
Interface for the definition of a single table column.
Properties
Name
Description
columnId: string
The unique ID of the column.
sortable?: boolean
Enables sorting for the column.
resizable?: boolean
Enables resizing of the column.
header: string
The text shown in the header row.
headerAlignment?: ColumnAlignmentType
Header alignment.
cell: (element: TRowData) => CellContentValue
Returns the rendered cell content for the current row.
cellAlignment?: ColumnAlignmentType
Alignment of the cell content.
width?: string
Optional column width, for example 8em.
tooltip?: (element: TRowData) => string
Optional tooltip callback.
showAsSingleLine?: boolean
Truncates the content to a single line.
footer?: string
Optional footer text.
footerAlignment?: ColumnAlignmentType
Footer alignment.
footerColumnSpan?: number
Optional number of columns the footer should span.
MatSortDefinition
Interface for the definition of sorting for one column.
Properties
Name
Description
columnId: string
The columnId of the column to sort.
direction: SortDirection
The sort direction.
RequestRowsRange
Interface defining the properties of a request for a range of rows.
Properties
Name
Description
startRowIndex: number
The index of the first row to return.
numberOfRows: number
The number of rows to return.
Page
Interface defining the properties of a page of rows returned from the datastore.
Properties
Name
Description
content: T[]
The array of requested rows.
startRowIndex: number
The index of the first row returned.
returnedElements: number
The number of rows in content.
totalElements: number
The number of rows in the unfiltered datastore.
totalFilteredElements: number
The number of rows after filtering.
Type Aliases
ColumnAlignmentType
typeColumnAlignmentType='left'|'center'|'right';
ColumnDisplayType
How the column should be rendered (as text, mail-to link or as image).
Abstract class used as base for harnesses that interact with a mat-datatable row.
Methods
async getCells
Gets a list of 'MatRowCellHarness', 'MatHeaderCellHarness' or 'MatFooterCellHarness' for all cells in the row.
filter: CellHarnessFilters = {}
A set of criteria that can be used to filter a list of cell harness instances.
Returns
Promise<Cell[]>
A filtered list of MatRowCellHarness for the cells in the row.
async getCellTextByColumnName
Gets the text inside the row organized by columns.
Returns
Promise<MatRowHarnessColumnsText>
The text inside the row organized by columns.
async getCellTextByIndex
Gets the text of the cells in the row.
Parameters
filter: CellHarnessFilters = {}
A set of criteria that can be used to filter a list of cell harness instances.
Returns
Promise<string[]>
The text of the cells in the row.
static async rowCellsContentMatch
Checks if the values of the table row columns given in the 'value' parameter, match the given column values. Only columns defined in the pattern are inspected.
Parameters
value: MatRowHarnessColumnsText | Promise | null
The nullable object defining all columns of a row and their values used for the checks. Alternatively a Promise resolving to the nullable object.
pattern: Record<string, string | RegExp> | null
Object defining the columns and the values or RegExp expected to match. If 'pattern' is 'null', the value is expected to be 'null'.
to make footer turn on / off dynamically it is not sufficient to wrap the footer cell and row definitions in ng-container. Details see stackoverflow. The demo uses ngx-rerender.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
Fork the Project
Create your Feature Branch (git checkout -b feature/AmazingFeature)
Commit your Changes (git commit -m 'Add some AmazingFeature')
Push to the Branch (git push origin feature/AmazingFeature)
Open a Pull Request
Changelog
The project uses 'standard-version' to create the changelog. To enable this system, commit messages are linted before commits are executed by git.
To enable this system you have to run the following scripts in your local repository home directory: