CollapseGroup Angular 2 Kendo Grid

时间:2018-01-04 09:44:41

标签: angular kendo-grid grouping

我想在点击按钮时折叠分组的行。我尝试了以下代码。

    @ViewChild(GridComponent) grid: GridComponent;
       close(); {
       for (let m = 0; m < 5; m = m + 1) {
          this.grid.groupCollapse(m.toString());
       }
    }

但是我收到编译错误,说#34;声明预期。&#34;我也导入了 GridComponent 。有人可以为此提供帮助吗?

我也尝试过这种方式;

    public collapseRows(grid: GridComponent): void {
       for (let m = 0; m < 5; m = m + 1) {
          grid.collapseGroup(m.toString());
       }
    }

我无法获得网格的值。它&#34; 未定义&#34;。如何通过&#34;网格&#34;这个方法。

由于

1 个答案:

答案 0 :(得分:1)

可以从ViewChild获取对Grid的引用:

<button class="k-button" (click)="collapseGroups()">Collapse All</button>
<br /><br />
<kendo-grid #grid...

@ViewChild('grid') private grid;
...     
public collapseGroups() {
// loop through the groups of the groped data and call closeGroup() for each group
this.gridView.data.forEach((gr, idx) => this.grid.collapseGroup(idx.toString()));
}

EXAMPLE

...或直接将模板引用变量传递给自定义方法:

<button class="k-button" (click)="collapseGroups(grid)">Collapse All</button>
<br /><br />
<kendo-grid #grid
...        >

EXAMPLE