How do I mock data to be chosen in PrimeNG's datatable?
@Component({
selector: 'p-dataTable',
template: `...`
})
class MockDataTableComponent {
@Input() value;
@Input() selection;
@Output() selectionChange = new EventEmitter();
click( rows: number) {
this.selection = rows;
return this.selection;
}
}
@Component({
selector: 'data-table',
template: `<p-dataTable #datatable></p-dataTable>`
})
class MyTableComponent {
@ViewChild('datatable') datatable;
}
How do I manually set a values to the mocked selection in PrimeNG? I want to assign a value to selection like
this.selection[0]['name'] = "John Doe";
this.selection[0]['age'] = 30;
How do I do this?
Just pass your initial selection into <p-dataTable>
.
@Component({
selector: 'p-dataTable',
template: `...`
})
class MockDataTableComponent {
@Input() value;
@Input() selection;
@Output() selectionChange = new EventEmitter();
click( rows: number) {
this.selection = rows;
return this.selection;
}
}
@Component({
selector: 'data-table',
template: `<p-dataTable [selection]="mockSelection" #datatable></p-dataTable>`
})
class MyTableComponent {
mockSelection = [];
constructor(){
this.mockSelection[0]={};
this.mockSelection[0]['name'] = "John Doe";
this.mockSelection[0]['age'] = 30;
}
@ViewChild('datatable') datatable;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.