Inline template ngx-datatable-column do not work, when passed to a wrapper component via ng-content or ng-container *ngTemplateOutlet
See original GitHub issueI’m submitting a bug report
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter
Current behavior
Inline templates of <ngx-datatable-column>
are not rendered inside of <ngx-datatable>
tag when passed to a wrapper component like
<my-wrapper [page]="page">
<ngx-datatable-column [flexGrow]="1" name="name" ></ngx-datatable-column>
</my-wrapper>
via ng-content
<ngx-datatable
[rowHeight]="100"
[columnMode]="'flex'"
[rows]="page.items"
[count]="page.items.length"
[offset]="page.currentPage"
[limit]="page.pageSize"
[scrollbarV]="true"
[virtualization]="false">
<ng-content></ng-content>
</ngx-datatable>
_internalColumns are undefined, because @ContentChildren returns 0 elements.
@ContentChildren(DataTableColumnDirective)
set columnTemplates(val: QueryList<DataTableColumnDirective>)
Expected behavior ngx-datatable have to be able to get inline column templates from ng-content, because it is needed for reuseability
Reproduction of the problem Create a wrapper component and pass ngx-datatable-column to it via ng-content;
Minimal demo can be found here https://plnkr.co/edit/m5lV9wvhrwjqrnMlq8DB?p=preview
What is the motivation / use case for changing the behavior? Wrapper components are important because of reusability. We have to be able to incapsulate helper functions as rowClass, cellClass, selected internally and only pass markup and items to the datatable.
Please tell us about your environment: Windows 10
Table version: 11.1.7 Angular version: Angular 5.2.0, Angular Cli 1.6.2
-
Browser: all
-
Language: all
Workaround:
I was able to insert columns via getting ContentChildren inside of wrapper component, but I think this is a dirty hack.
@ViewChild(DatatableComponent) datatable: DatatableComponent;
@ContentChildren(DataTableColumnDirective) val: QueryList<DataTableColumnDirective>;
ngOnInit() {
// workaround of ng-content
setTimeout(() => {
this.datatable.columnTemplates = this.val;
});
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:18
- Comments:7 (1 by maintainers)
Top GitHub Comments
I think, that you want use ngx-datatable-column 1 times, without Ctrl+C/Ctrl+V every times. You can use NgTemplate.
Create component wraper for you ngx-datatable: <wrp-table-component>
.html
wrp-table.component.ts
And now you can use that component:
Inside you component
This issue is not directly related to ngx-datatable. Angular does not support content projection via ng-content more than 2 levels deep. Ref: https://github.com/angular/angular/issues/8563