无法获取数据表中未定义的属性

问题描述 投票:0回答:1

我正在编写一个代码,其中用户搜索字母,然后将与该字母有关的所有问题动态填充到表中。

基本上,我要实现的功能是用获得的结果重新填充表。我在网上寻找如何执行此操作,并使用了angular-datatables模块。

我的html代码是

<div name="searchComponent" *ngIf="isEmpty==false && searchBool==false" class="table-responsive table table-striped" id="table1">
            <table class="table" id="searchTable" datatable [dtOptions]="dtOptions"
            [dtTrigger]="dtTrigger" matSort (matSortChange)="sortData($event)">
                <thead>
                    <tr>
                        <th id="title" mat-sort-header="title">Title</th>
                        <th id="reporter" mat-sort-header="reporter">Reporter</th>
                        <th id="assigned" mat-sort-header="assignto">Assigned To</th>
                        <th id="description" mat-sort-header="description">Description</th>
                        <th id="status" mat-sort-header="status">Status</th>
                        <th id="action" colspan="2">Action</th>
                    </tr>
                </thead>
                <tbody id="table-body">
                    <tr class="row1" (click)="view(i)" *ngFor="let object of sortedIssues | paginate:{ itemsPerPage: 5, currentPage: p };let i of index">
                        <td>{{object.title}}</td>
                        <td>{{object.reporter}}</td>
                        <td>{{object.assignto}}</td>
                        <td>{{object.description}}</td>
                        <td>{{object.status}}</td>
                        <td><button id="edit" class="btn btn-primary" (click)="$event.stopPropagation();edit(i)">Edit</button></td>
                        <td><button id="delete" class="btn btn-primary" (click)="$event.stopPropagation();delete(i)">Delete</button></td>
                    </tr>
                </tbody>
            </table>
            <pagination-controls (pageChange)="p = $event"></pagination-controls>
        </div>

并且所需的打字稿代码为

import{DataTableDirective} from 'angular-datatables'
 @ViewChild(DataTableDirective,{static:false})
    datatableElement: DataTableDirective;
    dtOptions: DataTables.Settings = {};
    dtTrigger: Subject<any> = new Subject();

 onKey(event: any) { // without type info
      let data={
        identifier:this.searchForm.get('search').value
      }
      this.appService.search(data).subscribe(
        data=>{
          this.issuesCollection=data.data
          setTimeout(()=>{
            this.renderer()
          },2000)
          // $('#searchTable').DataTable().destroy
          // this.dtTrigger.next()
        }
      )
    }  

    renderer=()=>{
      console.log(this.datatableElement)
      this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
        //dtInstance.draw(true);
        dtInstance.destroy()
        this.dtTrigger.next()
     });
        }

我收到此错误

I am getting this error

有人被困,无法在线找到任何解决方案,请有人帮我提前Thnxx

angular search html-table datatable angular6
1个回答
0
投票

通过查看您的代码段,错误引用了以下行:this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {

尝试添加以下内容:

ngAfterViewInit() {
   this.dtTrigger.next();
}

该操作将初始化触发器,否则将不创建dtInstance

© www.soinside.com 2019 - 2024. All rights reserved.