NGX-Datatables. How to get current table instance?

可紊 提交于 2020-06-29 04:06:10

问题


I have component with table, that receive RowData from another component by @Input. How can i get instance of current table.

That's part of my html

<ngx-datatable
        class="material"
        [rows]="inputData"
        [columns]="columns">
</ngx-datatable>

And component ts

export class GridComponent implements OnChanges {
 @Input() inputData: [object];

 columns1 = [
  { prop: 'name' },
  { name: 'Gender' },
  { name: 'Company' }
 ];
}

回答1:


@Viewchild is the correct method, but you should be using it another way.

Here is what you want to do.

Html:

<ngx-datatable
        #firstTable  
        class="material"
        [rows]="inputData"
        [columns]="columns">
</ngx-datatable>

<ngx-datatable
        #secondTable  
        class="material"
        [rows]="inputData"
        [columns]="columns">
</ngx-datatable>

Component.ts:

export class GridComponent implements OnChanges {
 @Input() inputData: [object]; // This line doesn't look right

 @ViewChild('firstTable') myTable1: DatatableComponent;
 @ViewChild('secondTable') myTable2: DatatableComponent;

 columns1 = [
  { prop: 'name' },
  { name: 'Gender' },
  { name: 'Company' }
 ];
}

You can take a look at this page for reference: http://learnangular2.com/viewChild/

Addition:

You can also use @ViewChildren that selects all of the elements, depending on your needs, docs here: https://angular.io/api/core/ViewChildren



来源:https://stackoverflow.com/questions/47072556/ngx-datatables-how-to-get-current-table-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!