-
-
Notifications
You must be signed in to change notification settings - Fork 932
/
register-data-table-component.ts
54 lines (53 loc) · 1.84 KB
/
register-data-table-component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { APP_INITIALIZER } from '@angular/core';
import {
DataTableComponentConfig,
DataTableCustomComponentService,
} from '../shared/components/data-table-2/data-table-custom-component.service';
/**
* @description
* Allows you to override the default component used to render the data of a particular column in a DataTable.
* The component should implement the {@link CustomDataTableColumnComponent} interface. The tableId and columnId can
* be determined by pressing `ctrl + u` when running the Admin UI in dev mode.
*
* @example
* ```ts title="components/custom-table.component.ts"
* import { Component, Input } from '\@angular/core';
* import { CustomColumnComponent } from '\@vendure/admin-ui/core';
*
* \@Component({
* selector: 'custom-slug-component',
* template: `
* <a [href]="'https://example.com/products/' + rowItem.slug" target="_blank">{{ rowItem.slug }}</a>
* `,
* standalone: true,
* })
* export class CustomTableComponent implements CustomColumnComponent {
* \@Input() rowItem: any;
* }
* ```
*
* ```ts title="providers.ts"
* import { registerDataTableComponent } from '\@vendure/admin-ui/core';
* import { CustomTableComponent } from './components/custom-table.component';
*
* export default [
* registerDataTableComponent({
* component: CustomTableComponent,
* tableId: 'product-list',
* columnId: 'slug',
* }),
* ];
* ```
*
* @docsCategory custom-table-components
*/
export function registerDataTableComponent(config: DataTableComponentConfig) {
return {
provide: APP_INITIALIZER,
multi: true,
useFactory: (dataTableCustomComponentService: DataTableCustomComponentService) => () => {
dataTableCustomComponentService.registerCustomComponent(config);
},
deps: [DataTableCustomComponentService],
};
}