kendo组件封装template/component使用
kendo component encapsulation template/component use
是否可以通过 ng-content 或 TemplateRef 或类似工具嵌入自定义列定义?我一直在通过站点上可用的 Kendo UI Grid plunker 进行测试(http://www.telerik.com/kendo-angular-ui/components/grid/) as well as 但无济于事。我也尝试过 ng-content select 但也没有。非常感谢任何帮助,谢谢!
@Component({
selector: 'test-component',
template:
`
<kendo-grid [data]="Data">
<kendo-grid-column></kendo-grid-column>
// ??? // <ng-content kendo-grid-column></ng-content> // [object Object]
// ??? // <kendo-grid-column ng-content></kendo-grid-column> // [object Object]
</kendo-grid>
`
})
export class TestComponent {
@Input() Data: any;
}
@Component({
selector: 'my-app',
template: `
<test-component [Data]="gridData">
<kendo-grid-column field="ProductID" title="Product ID" width="120"></kendo-grid-column>
<kendo-grid-column field="ProductName" title="Product Name"></kendo-grid-column>
<kendo-grid-column field="UnitPrice" title="Unit Price" width="230"></kendo-grid-column>
<kendo-grid-column field="Discontinued" width="120">
<template kendoCellTemplate let-dataItem>
<input type="checkbox" [checked]="dataItem.Discontinued" disabled/>
</template>
</kendo-grid-column>
</test-component>
`
})
export class AppComponent { ... }
到 select 带有 ng-content
的 kendo-grid-column
元素,使用:
<ng-content select="kendo-grid-column"></ng-content>
参见this plunkr。
正如@rusev 在之前的评论中所回答的...这对我有用,谢谢!
The GridComponent is using ContentChildren
to select defined columns,
which does not work with transclusion. A possible workaround -
plnkr.co/edit/w6EgmZL5z8J6CvpjMl2h?p=preview
这是可以在 plunkr 中看到的答案
import { Component, Input, ContentChildren, ViewChild, ChangeDetectorRef } from '@angular/core';
import { ColumnComponent, GridComponent } from '@progress/kendo-angular-grid';
const resolvedPromise = Promise.resolve(null); //fancy setTimeout
@Component({
selector: 'test-component',
template:
`
<kendo-grid [data]="Data">
</kendo-grid>
`
})
export class TestComponent {
@Input() Data: any[];
@ContentChildren(ColumnComponent) columns;
@ViewChild(GridComponent) grid;
constructor(private cdr: ChangeDetectorRef ) {}
ngAfterContentInit() {
resolvedPromise.then(() => {
this.grid.columns.reset(this.columns.toArray());
});
}
}
@Component({
selector: 'my-app',
template: `
<test-component [Data]="gridData">
<kendo-grid-column field="ProductID" title="Product ID" width="120"></kendo-grid-column>
</test-component>
`
})
export class AppComponent { ... }
是否可以通过 ng-content 或 TemplateRef 或类似工具嵌入自定义列定义?我一直在通过站点上可用的 Kendo UI Grid plunker 进行测试(http://www.telerik.com/kendo-angular-ui/components/grid/) as well as
@Component({
selector: 'test-component',
template:
`
<kendo-grid [data]="Data">
<kendo-grid-column></kendo-grid-column>
// ??? // <ng-content kendo-grid-column></ng-content> // [object Object]
// ??? // <kendo-grid-column ng-content></kendo-grid-column> // [object Object]
</kendo-grid>
`
})
export class TestComponent {
@Input() Data: any;
}
@Component({
selector: 'my-app',
template: `
<test-component [Data]="gridData">
<kendo-grid-column field="ProductID" title="Product ID" width="120"></kendo-grid-column>
<kendo-grid-column field="ProductName" title="Product Name"></kendo-grid-column>
<kendo-grid-column field="UnitPrice" title="Unit Price" width="230"></kendo-grid-column>
<kendo-grid-column field="Discontinued" width="120">
<template kendoCellTemplate let-dataItem>
<input type="checkbox" [checked]="dataItem.Discontinued" disabled/>
</template>
</kendo-grid-column>
</test-component>
`
})
export class AppComponent { ... }
到 select 带有 ng-content
的 kendo-grid-column
元素,使用:
<ng-content select="kendo-grid-column"></ng-content>
参见this plunkr。
正如@rusev 在之前的评论中所回答的...这对我有用,谢谢!
The GridComponent is using
ContentChildren
to select defined columns, which does not work with transclusion. A possible workaround - plnkr.co/edit/w6EgmZL5z8J6CvpjMl2h?p=preview
这是可以在 plunkr 中看到的答案
import { Component, Input, ContentChildren, ViewChild, ChangeDetectorRef } from '@angular/core';
import { ColumnComponent, GridComponent } from '@progress/kendo-angular-grid';
const resolvedPromise = Promise.resolve(null); //fancy setTimeout
@Component({
selector: 'test-component',
template:
`
<kendo-grid [data]="Data">
</kendo-grid>
`
})
export class TestComponent {
@Input() Data: any[];
@ContentChildren(ColumnComponent) columns;
@ViewChild(GridComponent) grid;
constructor(private cdr: ChangeDetectorRef ) {}
ngAfterContentInit() {
resolvedPromise.then(() => {
this.grid.columns.reset(this.columns.toArray());
});
}
}
@Component({
selector: 'my-app',
template: `
<test-component [Data]="gridData">
<kendo-grid-column field="ProductID" title="Product ID" width="120"></kendo-grid-column>
</test-component>
`
})
export class AppComponent { ... }