Skip to content

Commit d6839d6

Browse files
authoredJun 6, 2024··
docs(angular-table): Adding documentation for custom component support. (#5590)
1 parent 3379a47 commit d6839d6

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
 

‎docs/framework/angular/angular-table.md

+54
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,58 @@ class CustomCellComponent {
214214
}
215215
```
216216

217+
Alternatively, you can render a component into a specific column header, cell, or footer by passing the component type
218+
to the corresponding column definitions. These column definitions will be provided to the `flexRender` directive along with the `context`.
217219

220+
```ts
221+
import {FlexRenderComponent} from "@tanstack/angular-table";
222+
223+
class AppComponent {
224+
columns: ColumnDef<Person>[] = [
225+
{
226+
id: 'select',
227+
header: () => TableHeadSelectionComponent<Person>,
228+
cell: () => TableRowSelectionComponent<Person>,
229+
},
230+
]
231+
}
232+
```
233+
234+
```angular2html
235+
<ng-container
236+
*flexRender="
237+
header.column.columnDef.header;
238+
props: header.getContext();
239+
let headerCell
240+
"
241+
>
242+
{{ headerCell }}
243+
</ng-container>
244+
```
245+
246+
Properties of `context` provided in the `flexRender` directive will be accessible to your component.
247+
You can explicitly define the context properties required by your component.
248+
In this example, the context provided to flexRender is of type HeaderContext.
249+
Input signal `table`, which is a property of HeaderContext together with `column` and `header` properties,
250+
is then defined to be used in the component. If any of the context properties are
251+
needed in your component, feel free to use them. Please take note that only input signal is supported,
252+
when defining access to context properties, using this approach.
253+
254+
```ts
255+
@Component({
256+
template: `
257+
<input
258+
type="checkbox"
259+
[checked]="table().getIsAllRowsSelected()"
260+
[indeterminate]="table().getIsSomeRowsSelected()"
261+
(change)="table().toggleAllRowsSelected()"
262+
/>
263+
`,
264+
// ...
265+
})
266+
export class TableHeadSelectionComponent<T> {
267+
//column = input.required<Column<T, unknown>>()
268+
//header = input.required<Header<T, unknown>>()
269+
table = input.required<Table<T>>()
270+
}
271+
```

0 commit comments

Comments
 (0)
Please sign in to comment.