{"id":17987802,"url":"https://github.com/dirkluijk/ngx-generic-material-tables","last_synced_at":"2025-03-25T22:32:33.698Z","repository":{"id":38711560,"uuid":"202730591","full_name":"dirkluijk/ngx-generic-material-tables","owner":"dirkluijk","description":"Utils for generic Angular Material tables","archived":false,"fork":false,"pushed_at":"2023-01-07T08:47:06.000Z","size":6808,"stargazers_count":10,"open_issues_count":26,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-08-03T08:00:03.596Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dirkluijk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-16T13:16:26.000Z","updated_at":"2023-05-17T16:01:22.000Z","dependencies_parsed_at":"2023-02-06T17:16:56.602Z","dependency_job_id":null,"html_url":"https://github.com/dirkluijk/ngx-generic-material-tables","commit_stats":null,"previous_names":[],"tags_count":3,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Fngx-generic-material-tables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Fngx-generic-material-tables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Fngx-generic-material-tables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Fngx-generic-material-tables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dirkluijk","download_url":"https://codeload.github.com/dirkluijk/ngx-generic-material-tables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222099608,"owners_count":16931447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-29T19:09:42.029Z","updated_at":"2024-10-29T19:09:42.100Z","avatar_url":"https://github.com/dirkluijk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Generic Angular Material Tables 🚀\n\n\u003e Sorting and filtering utils to create generic Angular Material tables\n\n[![NPM version](http://img.shields.io/npm/v/@dirkluijk/ngx-generic-material-tables.svg?style=flat-square)](https://www.npmjs.com/package/@dirkluijk/ngx-generic-material-tables)\n[![NPM downloads](http://img.shields.io/npm/dm/@dirkluijk/ngx-generic-material-tables.svg?style=flat-square)](https://www.npmjs.com/package/@dirkluijk/ngx-generic-material-tables)\n[![Build status](https://img.shields.io/travis/dirkluijk/ngx-generic-material-tables.svg?style=flat-square)](https://travis-ci.org/dirkluijk/ngx-generic-material-tables)\n[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)\n\n## Overview\n\n### What? 🤔\n\nA small set of utils to make [Angular Material Tables](https://material.angular.io/components/table) more generic.\n\n* Sorting based on column names, with nested property support using dot notation\n* Filtering based on column names, with nested property support using dot notation\n* Sorts string values case-insensitive\n* Filter only on displayed columns (case-insensitive and trimming the filter string)\n* Persisted sorting using SessionStorage\n* Reactive data source for RxJS Observables\n* Reloading functionality (for reactive data sources)\n\n### Why? 🤷‍♂️\n\nWhen using Angular Material Table, you may need more advanced sorting and filtering behaviour. That's why you usually end up with a lot of boilerplate code.\n\nThis library provides some utils to use consistent sorting and filtering behaviour for all your tables.\n\n## Installation 🌩\n\n##### npm\n\n```\nnpm install @dirkluijk/ngx-generic-material-tables --save-dev\n```\n\n##### yarn\n\n```\nyarn add @dirkluijk/ngx-generic-material-tables --dev\n```\n\n## Usage 🕹\n\n### GenericTableDataSource\n\nThe `GenericTableDataSource` allows you to use \"dot notation\" for your columns and benefit from the following features:\n\n* Only filter on the displayed columns (which you need to pass to it), using the dot notation\n* Use the sortable columns based on the values accessed using the dot notation\n\n```typescript\nimport { Component } from '@angular/core';\nimport { GenericTableDataSource } from '@dirkluijk/ngx-generic-material-tables'\n\n@Component({\n    template: `\n      \u003ctable mat-table [dataSource]=\"genericDataSource\" matSort gmtApplyMatSort\u003e\n        \u003cng-container matColumnDef=\"name\"\u003e\n          \u003cth mat-header-cell *matHeaderCellDef mat-sort-header\u003eName\u003c/th\u003e\n          \u003ctd mat-cell *matCellDef=\"let row\"\u003e\n              {{ row.name }}\n          \u003c/td\u003e\n        \u003c/ng-container\u003e\n\n        \u003cng-container matColumnDef=\"foo.bar\"\u003e\n          \u003cth mat-header-cell *matHeaderCellDef mat-sort-header\u003eFoo Bar\u003c/th\u003e\n          \u003ctd mat-cell *matCellDef=\"let row\"\u003e\n            {{ row.foo.bar }}\n          \u003c/td\u003e\u003e\n        \u003c/ng-container\u003e\n          \n        \u003ctr mat-header-row *matHeaderRowDef=\"displayedColumns\"\u003e\u003c/tr\u003e\n        \u003ctr mat-row *matRowDef=\"let row; columns: displayedColumns\"\u003e\u003c/tr\u003e\n    \u003c/table\u003e\n    `\n})\nexport class MyComponent {\n    public displayedColumns = ['name', 'foo.bar'];\n    public genericDataSource = new GenericTableDataSource\u003cYourRecordEntity\u003e(this.displayedColumns, [/** your data */]);\n}\n``` \n\n### Apply `MatSort` automatically\n\nUse the `gmtApplyMatSort` to automatically register the `MatSort` on the data source.\n\n```html\n\u003ctable mat-table [dataSource]=\"genericDataSource\" matSort gmtApplyMatSort\u003e\n  \u003c!-- ...  --\u003e\n\u003c/table\u003e\n```\n\nThis allows you to leave out the following code: \n\n```typescript\nViewChild(MatSort, {static: true}) sort: MatSort; // not needed anymore!\n\nngOnInit(): void {\n  this.dataSource.sort = this.sort; // not needed anymore!\n}\n```\n\n### Persisted sorting\n\nYou can persist the sorting actions to SessionStorage using the `gmtPersistedSort` directive.\nJust pass an additional identifier for your table in order to distinguish between multiple tables. \n\n```html\n\u003ctable mat-table [dataSource]=\"genericDataSource\" matSort gmtPersistedSort=\"my-table\"\u003e\n  \u003c!-- ...  --\u003e\n\u003c/table\u003e\n```\n\nThat's it!\n\n### ReactiveGenericTableDataSource\n\nEven more awesome is the reactive version of the `GenericTableDataSource`:\n\n* Pass the displayed columns, table data and filter data as `Observable` stream\n* Automatically reacts to changes\n* Provides `reload()` functionality\n* Provides `loading`/`success`/`failed` static properties\n* Provides `loading$`/`success$`/`failed$` Observable properties\n\n```typescript\nimport { ReactiveGenericTableDataSource } from '@dirkluijk/ngx-generic-material-tables'\n\nconst dataSource = new ReactiveGenericTableDataSource\u003cYourRecordEntity\u003e(\n  displayedColumns$,\n  yourTableData$,\n  yourFilter$ // (optional)\n);\n\ndataSource.reload();\n```\n\n### Custom filtering for specific columns / types\n\nIf you still want to have custom filtering for a specific column, filter value or column value,\nyou can pass a `ColumnFilterPredicate`:\n\n```typescript\nimport { defaultColumnFilterPredicate } from '@dirkluijk/ngx-generic-material-tables';\n\ndataSource.columnFilterPredicate = (value, filter, columnName) =\u003e {\n   // exact filter for this column\n  if (columnName === 'vehicle.number') {\n    return value.trim().includes(filter);\n  }\n\n  // custom filter for number values\n  if (typeof value === 'number') {\n    return String(yourFormatFn(value)).includes(filter);\n  }\n\n  return defaultColumnFilterPredicate(value, filter, columnName); // use default predicate for other cases\n};\n```\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/dirkluijk\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/2102973?v=4\" width=\"100px;\" alt=\"Dirk Luijk\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDirk Luijk\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/dirkluijk/@ngx-dirkluijk/generic-material-tables/commits?author=dirkluijk\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/dirkluijk/@dirkluijk/generic-material-tables/commits?author=dirkluijk\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkluijk%2Fngx-generic-material-tables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirkluijk%2Fngx-generic-material-tables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkluijk%2Fngx-generic-material-tables/lists"}