简体   繁体   English

Angular 2-PrimeNG Mock数据表选择

[英]Angular 2 - PrimeNG Mock Datatable Selection

How do I mock data to be chosen in PrimeNG's datatable? 我该如何模拟要在PrimeNG数据表中选择的数据?

@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? 如何在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> . 只需将您的初始选择传递到<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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM