angular - Kendo Angular 2 网格过滤器不可用

标签 angular kendo-ui-angular2

我使用这个 http://www.telerik.com/kendo-angular-ui/components/grid/data-binding/ 将 Kendo Grid 与 Angular 2 结合使用教程,但我没有在网格中找到过滤。如何使用 Angular 2 过滤我的 Kendo 网格?

最佳答案

我创建了这个 plunker您可以在其中按产品名称过滤网格。这是一个非常基本的例子:

import { Component } from '@angular/core';

import {
  GridDataResult,
  SortDescriptor,
  orderBy
} from '@progress/kendo-angular-grid';

@Component({
  selector: 'my-app',
  template: `
      <input type="text" [(ngModel)]="filter" (ngModelChange)="change()">
      <kendo-grid
          [data]="gridView"
          [sortable]="{ mode: 'multiple' }"
          [sort]="sort"
          (sortChange)="sortChange($event)"
        >
        <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>
  `
})
export class AppComponent {
    private filter: string;
    private sort: SortDescriptor[] = [];
    private gridView: GridDataResult;
    private products: any[] = [
      {
        "ProductID": 1,
        "ProductName": "Chai",
        "UnitPrice": 18.0000,
        "Discontinued": false
    },
       {
        "ProductID": 3,
        "ProductName": "Chai",
        "UnitPrice": 122.0000,
        "Discontinued": true
    }
                               ,{
        "ProductID": 2,
        "ProductName": "Chang",
        "UnitPrice": 19.0000,
        "Discontinued": false
    }];

    constructor() {
        this.loadProducts();
    }

    protected sortChange(sort: SortDescriptor[]): void {
        this.sort = sort;
        this.loadProducts();
    }

    private loadProducts(prods): void {
      const products = prods || this.products;
        this.gridView = {
            data: orderBy(products, this.sort),
            total: products.length
        };
    }

   private change(){
      this.loadProducts(this.products.filter(product => product.ProductName === this.filter));
   }

}

关于angular - Kendo Angular 2 网格过滤器不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39920644/

相关文章:

angular - ngFor 循环中的样式

Angular Material : SassError: Invalid CSS after “@include mat” : expected 1 selector or at-rule, 为 “.core();”

kendo-ui-angular2 - 如何为剑道对话 Action 添加回调

angular - 无法绑定(bind)到 'routerLink',因为它不是 'a' 的已知属性。尽管引用了路由器模块,但还是有错误

angular - 根据浏览器语言设置 Angular LOCALE_ID

html - 如何使面板栏可拖动 Angular

css - Angular 2 外部样式没有内联到标题

css - 为什么 ng-container 不响应样式?

angular - 新的 Angular 9 应用程序,带有 "ERROR in Cannot read property ' 标志“未定义”,在 Mac 上 "ng build"

angular - 用于 Angular2 Grid Web API 数据绑定(bind)的 Kendo UI