Home:ALL Converter>Angular 2 - PrimeNG Mock Datatable Selection

Angular 2 - PrimeNG Mock Datatable Selection

Ask Time:2016-10-24T09:03:21         Author:xiotee

Json Formatter

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?

Author:xiotee,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40209418/angular-2-primeng-mock-datatable-selection
yy