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.
Nat-Datatable implements a table with virtual scrolling, sorting and filtering. Only a minimal set of the functionality of ngx-datatable is implemented.
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.
The definition of the columns used in the table. The order of the definitions needs not to correspond to the order of the columns in the table. Default value: [].
Name
Description
@Input() displayedColumns: string[]
A list with the names of the columns in the table. The array contains the 'columnId' of the corresponding column definition. Default value: [].
Name
Description
@Input() rowSelectionMode: RowSelectionType
The type of row selection. Default value: 'none'.
Name
Description
@Input() dataStoreProvider: DataStoreProvider<T>
An object that connects the mat-datatable with the data source. The object must be the instance of a class implementing the DataStoreProvider interface. Default value: new EmptyDataStoreProvider<T>.
Name
Description
@Input() trackBy(): TrackByFunction<T>
A function that returns a value that identifies a single row. Default value: (index: number, item: T) => JSON.stringify(item).
Name
Description
withFooter: boolean
Whether the table has a footer row. Default value: true.
Emitted when the index of the first visible row changes.
Name
Description
totalRowsChanged: Observable<number>
Emitted when the total number of rows in the datastore changes (does not depend on any active filter).
Name
Description
filteredRowsChanged: Observable<number>
Emitted when the number of filtered rows changes.
Name
Description
activatedRow: T | undefined
Marks a row as 'active'.
Name
Description
selectedRows: T[]
Marks rows as 'selected'.
Name
Description
sortDefinitions: MatSortDefinition[]
Gets / sets the current sort definition.
Name
Description
filterDefinitions: FieldFilterDefinition<T>[]
Gets / sets the current filter definition.
Methods
scrollToRow
Scrolls to the given row.
Parameters
row: T
Row to show on the top of the current viewport.
reloadTable
Reloads the rows of the table.
Interfaces
DataStoreProvider
Interface for a component that fetches data from the datastore respecting sorting and filtering.
The component is generic; the given type is used to define the object for the row data.
Methods
getPagedData
Fetches data from the datastore respecting sorting and filtering.
Parameters
rowsRange: RequestRowsRange
The range of rows to fetch.
sorts: FieldSortDefinition[]
The sort definitions to use.
filters: FieldFilterDefinition[]
The filter definitions to use.
Returns
Observable<Page>
Emitting fetched data from the datastore.
MatColumnDefinition
Interface for the definition of a single table column.
Properties
Name
Description
columnId: string
The ID of the column.
sortable: boolean
Whether this column can be used for sorting. By default a column is not sortable.
resizable: boolean
Whether this column can be resized. By default a column is not resizable.
header: string
The text in the header row of a column.
headerAlignment: ColumnAlignmentType
The alignment of the header row of a column.
cell: (element: TRowData) => string
The function to get the content of a cell.
cellAlignment: ColumnAlignmentType
The alignment of a data row in a column.
width: string
The width of the column.
tooltip: (element: TRowData) => string
The function to get the tooltip for a cell.
showAsMailtoLink: boolean
Whether this cell should be shown a 'mailto' link. By default a column is not shown as mailto link.
showAsSingleLine: boolean
Whether this cell should be truncated to a single line. By default multiline text in a column is not shown as a single line.
footer: string
The text in the footer row of a column.
footerAlignment: ColumnAlignmentType
The alignment of the footer row of a column.
footerColumnSpan: number
The number of columns a footer should span. By default a footer spans 1 column.
MatSortDefinition
Interface for the definition of the sorting of 1 table column.
Properties
Name
Description
columnId: string
The 'columnId' of the column to use for sorting.
direction: SortDirection
The direction used to sort the column.
RequestRowsRange
Interface defining the properties of a requests 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 the requested rows.
startRowIndex
The index of the first row returned.
returnedElements
The number of rows in 'content'.
totalElements
The number of rows in the unfiltered data store.
totalFilteredElements
The number of rows after filtering.
Type Aliases
ColumnAlignmentType
The alignment of the content of a column
type ColumnAlignmentType = "left" | "center" | "right";
FieldFilterDefinition
The definition of a parameter filtering for the column identified by the given 'fieldName'.
type FieldFilterDefinition = StrictUnion<(FieldFilterDefinitionSimple<T> | FieldFilterDefinitionRange<T>)>;
FieldFilterDefinitionRange
The definition of a parameter filtering for a range of values.
type FieldFilterDefinitionSimple = { fieldName: keyof T valueFrom: string | number | Date valueTo: string | number | Date };
FieldFilterDefinitionSimple
The definition of a parameter filtering for a single value.
type FieldFilterDefinitionSimple = { fieldName: keyof T value: string | number | Date };
FieldSortDefinition
The definition of a single sort parameter.
type FieldSortDefinition = { fieldName: keyof T sortDirection: SortDirectionAscDesc };
RowSelectionType
How many rows can be selected.
type RowSelectionType = 'none' | 'single' | 'multi';
SortDirectionAscDesc
The direction of a sort.
type SortDirection = 'asc' | 'desc';
API Testing Harnesses
import { MatDatatableHarness } from '@bepo65/mat-datatable/testing';
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: