I want to expand row directly from an typescript method, i've try with @viewchild but it doesn't work :
HTML:
<p-dataTable [value]="array" [responsive]="true" expandableRows="true" #dt
(onRowClick)="dt.toggleRow($event.data)">
<template let-test pTemplate="rowexpansion">
<div class="ui-grid ui-grid-responsive ui-fluid">
<div class="ui-grid-row">
Bouh !
</div>
</div>
</template>
<p-column field="name" header="Vin"></p-column>
<p-column field="company" header="Year"></p-column>
</p-dataTable>
<button class="btn" (click)="addComment()">
<p>add comment</p>
</button>
Typescript:
import { DataTable } from 'primeng/components/datatable/datatable';
export class MyAwesomeComponent implements OnInit {
@ViewChild('dt') datatable : DataTable;
addComment(): void {
console.log(this.datatable);
this.datatable.toggleRow(1);
}
row doesn't expand, if someone could tell me how to do the same thing that (onRowClick) event do but inside a typescript method, i will be grateful.
There is a toggleRow method at the level of the data table that takes row data, passed as a parameter:
You can use this just for toggling purposes (please make sure you have defined [pSelectableRow]="rowData" in your template body.
If you needed something more customized, then you can, defined a reference called #dtEntry :-
Somewhere in your code - notice we are passing in (rowdata, dtEntry) above
You might have the following script in your code to handle onRowSave.
}
You can add another data table or view after last column like below code
Try this:
There is a property
expandedRows
that is an array of all current expanded rows. You should be able to add / remove your row to this list to toggle row expansion.You will need to have:
and
Simple plunker but you get the idea... https://plnkr.co/edit/Zra8UUMv4XQCv0lbRbMg?p=preview