Javascript 角度数据表:多个数据表单个列筛选器不工作

Javascript 角度数据表:多个数据表单个列筛选器不工作,javascript,jquery,angular,datatables,angular-datatables,Javascript,Jquery,Angular,Datatables,Angular Datatables,角度数据表采用角度方式,多个数据表过滤器不工作,只有一个表工作 我有两个表和不同的API数据。我正在尝试实现单个列过滤器。只有一个表正在工作,第二个表无法进行筛选。任何建议请 ngAfterViewInit(): void { this.datatableElementList.forEach(datatableElement=>{ this.dtTrigger1.subscribe(() => { this.datatableElement.dtIn

角度数据表采用角度方式,多个数据表过滤器不工作,只有一个表工作

我有两个表和不同的API数据。我正在尝试实现单个列过滤器。只有一个表正在工作,第二个表无法进行筛选。任何建议请

  ngAfterViewInit(): void {
    this.datatableElementList.forEach(datatableElement=>{
    this.dtTrigger1.subscribe(() => {
      this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
        dtInstance.columns().every(function () {
          const that = this;
          $("input", this.footer()).on("keyup change", function () {
            if (that.search() !== this["value"]) {
              that.search(this["value"]).draw();
            }
          });
        });
      });
    });
    this.dtTrigger2.subscribe(() => {
      this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
        dtInstance.columns().every(function () {
          const that = this;
          $("input", this.footer()).on("keyup change", function () {
            if (that.search() !== this["value"]) {
              that.search(this["value"]).draw();
            }
          });
        });
      });
    });
  });
  }

我只是快速查看一下您的代码,但是如果您有多个表,则需要使用ViewChildren(ViewChildren获取第一个表)。您需要在ngAfterViewInit中使用

@ViewChildren(DataTableDirective) datatableElementList: QueryList<DataTableDirective>;
ngAfterViewInit()
{
   this.datatableElementList.forEach(datatableElement=>{
           ..your code with each "datatableElement"...
   })
}
@ViewChildren(DataTableDirective)datatableElementList:QueryList;
ngAfterViewInit()
{
this.datatableElementList.forEach(datatableElement=>{
…您的代码与每个“datatableElement”。。。
})
}

我只是快速查看一下您的代码,但是如果您有多个表,则需要使用ViewChildren(ViewChildren获取第一个表)。您需要在ngAfterViewInit中使用

@ViewChildren(DataTableDirective) datatableElementList: QueryList<DataTableDirective>;
ngAfterViewInit()
{
   this.datatableElementList.forEach(datatableElement=>{
           ..your code with each "datatableElement"...
   })
}
@ViewChildren(DataTableDirective)datatableElementList:QueryList;
ngAfterViewInit()
{
this.datatableElementList.forEach(datatableElement=>{
…您的代码与每个“datatableElement”。。。
})
}