我正在尝试在我的 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;
}
}