0

我正在尝试在我的 Angular 2 应用程序中使用 ngx-datatables。我尝试按照示例进行操作: https ://github.com/swimlane/ngx-datatable/blob/master/demo/basic/filter.component.ts 我收到错误消息:“无法设置未定义的属性'偏移'”每当我在过滤器框中输入。我尽可能地将其删除,并对行进行硬编码以尝试查看问题所在,但我无法弄清楚。任何帮助表示赞赏。

零件:

import { Component, ViewChild } from '@angular/core';
import { DatatableComponent } from '../../../node_modules/@swimlane/ngx-datatable/src/components/datatable.component';


@Component({
    selector: 'app-school-list',
    template: `
    <input type='text'
      placeholder='Type to filter the name column...'
      (keyup)='updateFilter($event)' />
    <ngx-datatable
      #table
      [columns]="columns"
      [footerHeight]="50"
      [limit]="5"
      [rows]='rows'>
    </ngx-datatable>
  `
})

export class SchoolListComponent {
    temp = [];
    columns = [
        { prop: 'name' },
        { name: 'Gender' },
        { name: 'Company' }
    ];
    rows = [
        { name: 'Austin', gender: 'Male', company: 'Swimlane' },
        { name: 'Bobby', gender: 'Male', company: 'KFC' },
        { name: 'Christina', gender: 'Female', company: 'Burger King' },
        { name: 'Dustin', gender: 'Male', company: 'Swimlane' },
        { name: 'Ellie', gender: 'Female', company: 'KFC' },
        { name: 'Flower', gender: 'Female', company: 'Burger King' },
        { name: 'Gordon', gender: 'Male', company: 'Swimlane' },
        { name: 'Houston', gender: 'Male', company: 'KFC' },
        { name: 'Ian', gender: 'Male', company: 'Burger King' }
    ];

    @ViewChild(DatatableComponent) table: DatatableComponent;

    constructor() {
        this.temp = this.rows;
    }

    updateFilter(event) {
        const val = event.target.value.toLowerCase();

        const temp = this.temp.filter(function (d) {
            return d.name.toLowerCase().indexOf(val) !== -1 || !val;
        });

        this.rows = temp;
        this.table.offset = 0;
    }
}
4

1 回答 1

0

@yurzui 谢谢。导入错误。在示例中,它是:“来自'../../src/components/datatable.component';”。

我试着用我的方法做到这一点,只是我的文件夹是几个目录。他们的例子都没有这样做。他们需要更好的文档。

于 2017-05-12T15:22:06.547 回答