![](/img/trans.png)
[英]Passing Kendo Angular grid column templates to a parent component hosting the grid
[英]Angular 2 Kendo UI pass column definitions to grid from parent component
我目前正在使用Angular 4和Kendo UI for Angular進行項目。 我們有多個劍道網格應該使用相同的配置(工具欄,分頁,頁腳模板等)
我決定使用網格的默認配置來制作組件,因此我們到處沒有相同的代碼。
所有網格之間的主要區別是列定義。 所以我的想法是將它們作為內容傳遞給我的包裝器組件,然后在kendo網格中添加ng-content。
所以我現在有:
main.component.ts
@Component({
template: "<grid-wrapper>
<kendo-grid-column field="projectName">
<ng-template kendoGridHeaderTemplate>
<span>Project Name</span>
</ng-template>
</kendo-grid-column>
</grid-wrapper>"
})
export class MainComponent {
}
wrapper.component.ts
@Component({
template: "<div>
<!-- Some code for buttons shown above the grid -->
<kendo-grid [data]="data"
[pageSize]="pageSize"
[sortable]="{mode: 'single'}"
<ng-content></ng-content>
<!-- templates and components for paging, toolbar, ... -->
</kendo-grid>
</div>",
selector: "grid-wrapper"
})
export class WrapperComponent {
private data: GridDataResult;
private pageSize: number = 10;
// ...
// Some code for filling the data
// ...
}
在調試kendo網格時,我注意到GridComponent使用@ContentChildren獲取列,但是此集合為空。
有人知道出什么問題了嗎? 或關於如何更好地做到這一點的任何建議?
最好的問候,BillieTK。
在以下位置得到了答案:
看看那里顯示的塞子。 為我工作! GridComponent使用ContentChildren選擇已定義的列,該列不適用於包含。 可能的解決方法-plnkr.co/edit/w6EgmZL5z8J6CvpjMl2h?p=preview – rusev 1月5日,8:51
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.