ngx-datatable - 过滤列无法正常工作?

时间:2018-01-23 12:23:27

标签: angular typescript

我为名称列创建了过滤器,如文档:

https://github.com/swimlane/ngx-datatable/blob/master/demo/basic/filter.component.ts

当在输入控件中键入一些文本时,我从表中获得了这个好结果,但是当我从输入字段中删除文本或开始键入其他文本时,数据表需要刷新第一个状态或显示新值。这不起作用...只是消息“没有数据”,每次我必须刷新页面进行新的搜索..

threat.component.ts

//use mPDF;  #Php 5.6
use Mpdf\Mpdf; #Php 7.0

threat.component.html

import { Component, Inject, ChangeDetectorRef, OnInit, Input, ViewChild } from '@angular/core';

import { Threat } from '../../../../models/threat.model';
import { ThreatService } from '../../../../services/threat.service';
import { DatatableComponent } from '@swimlane/ngx-datatable';

@Component({
 selector: 'app-threat',
 templateUrl: './threat.component.html',
})
export class ThreatComponent implements OnInit {
public showLoadingIcon: boolean;
private ref: ChangeDetectorRef;

threats: Threat[] = [];
temp: Threat[] = [];

@ViewChild(DatatableComponent) table: DatatableComponent;

constructor(ref: ChangeDetectorRef,
    private threatService: ThreatService
) {
    this.ref = ref;
    this.showLoadingIcon = false;

    this.temp = this.threats;
}

ngOnInit() {
    this.onGetThreats();
}

onGetThreats() {
    this.threatService.getThreats()
        .subscribe(
        response => {
            this.threats = response.items;
        });
}

filterThreatName(event: any){
    const val = event.target.value.toLowerCase();

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

    this.threats = temp;
    this.table.offset = 0;
 }
}

1 个答案:

答案 0 :(得分:0)

我认为偏移量不起作用,因为偏移量是在您更改过滤器后将其带回到第一页。