简体   繁体   English

如何使用Angular 2在Kendo Grid中显示和隐藏明细行

[英]How to show and hide Detail Row in Kendo Grid with Angular 2

I have an angular 2 kendo grid component that looks like this 我有一个看起来像这样的角度2剑道网格组件

<kendo-grid [data]="gridView"
        [selectable]="true"
        [pageSize]="pageSize"
        [skip]="skip"
        [pageable]="true"
        [sortable]="{ mode: 'multiple' }"
        [sort]="sort"
        (pageChange)="pageChange($event)">
<kendo-grid-column Title="Select">
    <template kendoCellTemplate let-dataItem>
        <input type="checkbox" (change)="onContactsSelect(dataItem.accountId, $event)"/>            
    </template>        
</kendo-grid-column>

<kendo-grid-column field="accountId" title="{{result.accountColumn}}" ></kendo-grid-column>
<kendo-grid-column field="name" title="{{result.nameColumn}}"></kendo-grid-column>
<kendo-grid-column field="address" title="{{result.addesssColumn}}"></kendo-grid-column>
<kendo-grid-column field="state" title="{{result.statusColumn}}"></kendo-grid-column>
<kendo-grid-column field="customField1" title="{{result.customField1Column}}"></kendo-grid-column>
<kendo-grid-column field="customField2" title="{{result.customField2Column}}"></kendo-grid-column>
<kendo-grid-column field="timeStamp" title="{{result.timeStampColumn}}"></kendo-grid-column>   
<template kendoDetailTemplate let-dataItem>
        <section *ngIf="!dataItem.isValid">
            <article>{{dataItem.errorMessage}}</article>
        </section>
</template>

I do want to show the detail row (and the details k-plus and k-minus signs to toggle between open and closing the detailed row) only when there is an error message or only when the dataitem is invalid. 我确实想仅在出现错误消息或仅当数据项无效时才显示明细行(以及明细k加号和k减号在打开和关闭明细行之间切换)。

Right now the toggle buttons appear on all rows regardless of the dataitem is valid or not. 现在,无论数据项是否有效,切换按钮都会出现在所有行上。

Any pointers would be helpful. 任何指针都会有所帮助。

I know this is a slightly older thread, but I did manage to come up with the solution for how to do this: 我知道这是一个稍旧的线程,但是我确实设法提出了解决方案:

First get rid of 首先摆脱

<section *ngIf="!dataItem.isValid>
    ...
</section>

You want: 你要:

<template kendoDetailTemplate let-dataItem>
          [kendoGridDetailTemplateShowIf]="condition"
        ...whatever you want to show based on the condition...
</template>

The condition that is next to kendoGridDetailTemplateShowIf above is a function on the typescript file with the same name, it will take whatever the dataitem is as a parameter (note that you do not write it is a function with the parameter in HTML). 上面的kendoGridDetailTemplateShowIf旁边的条件是具有相同名称的打字稿文件上的函数,它将使用dataitem作为参数(请注意,您不使用HTML中的参数将其编写为函数)。 The function in the TS file, should return a boolean where true will display the expand button and false will not and therefore either show or not show the detail template. TS文件中的函数应返回一个布尔值,其中true将显示展开按钮,false将不显示,因此将显示或不显示详细信息模板。

So in the typescript file: 因此在打字稿文件中:

condition(dataItem: any) : boolean {
    return !dataItem.isValid;
}

Hope this helps. 希望这可以帮助。

As a side note (not relevant to the answer, but a personal complaint so feel free to skip) this just one more example where Telerik is horrible at documentation and even though you can figure it out with the help of sites like this, development with their frameworks can be painful. 附带说明(与答案无关,但有个人投诉,可以随时跳过),这只是一个例子,其中Telerik的文档令人恐惧,即使您可以借助类似的网站解决该问题,他们的框架可能很痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM