nested table using angular-datatables,m facing either placement of child row or dtOptions of main table are not laoding.
See original GitHub issueI am creating a table using angular-datatables in Angular 6. I am trying for nested tables like showing another table on expand of td. But the expanded row always adding at the top of the main table rows.
dtOptions = {
pagingType: 'full_numbers',
pageLength: 5,
processing: true
};
mainData = [
{'plus':'','ID':1,'FName':'AAA','SName':'A','Place':'ID'},
{'plus':'','ID':2,'FName':'BBB','SName':'B','Place':'SG'},
{'plus':'','ID':3,'FName':'CCC','SName':'C','Place':'HK'},
{'plus':'','ID':4,'FName':'DDD','SName':'D','Place':'CN'}
];
getRow(row){
console.log("data",row);
row.expand = true;
}
``<div class="row" style="margin:0px;">
<div class="col-md-12"><h6>Nested Table</h6></div>
<div class="col-md-12">
<table datatable [dtOptions]="dtOptions" class="table table-striped">
<thead>
<tr>
<td></td>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>Place</td>
</tr>
</thead>
<tbody>
<ng-template ngFor let-row [ngForOf]="mainData" let-i="index">
<tr class="sub_{{i}}">
<td (click)="getRow(row)"><i class="fa fa-plus"></i></td>
<td>{{row.ID}}</td>
<td>{{row.FName}}</td>
<td>{{row.SName}}</td>
<td>{{row.Place}}</td>
</tr>
<tr class="sub_{{i}} secondrow" *ngIf="row.expand">
<table datatable [dtOptions]="dtOptions" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>SSS</td>
</tr>
</tbody>
</table>
</tr>
</ng-template>
</tbody>
</table>
</div>
</div>
But I want show the nested table on expand of particular row like below the each row.
like this. Please suggest me, what I am missing. And If I do like below ,the nested row coming properly but dtOptions of main table are not loading.
<tbody>
<ng-template ngFor let-row [ngForOf]="mainData" let-i="index">
<tr class="sub_{{i}}">
<td (click)="getRow(row)">
<i class="fa fa-plus" *ngIf="!row.expand"></i>
<i class="fa fa-minus" *ngIf="row.expand"></i>
</td>
<td>{{row.ID}}</td>
<td>{{row.FName}}</td>
<td>{{row.SName}}</td>
<td>{{row.Place}}</td>
</tr>
<tr></tr>
<tr class="sub_{{i}} secondrow" *ngIf="row.expand">
<table datatable [dtOptions]="dtOptions" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>SSS</td>
</tr>
</tbody>
</table>
</tr>
</ng-template>
</tbody>
Ataching the reference images.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
angular-datatables in angular 6 , nested rows alignment issue ...
I am trying for nested tables like showing another table on expand of td.But the expanded row always adding at the top of...
Read more >How to do Datatables Nested tables with Angular Integration
When the screeen size decreases, with datatable, it automatically moves the excessive columns into child rows, I'd like to keep that feature.
Read more >Table - PrimeNG - PrimeFaces
Table is a template driven component with named templates such as header and body that we've used so far. Templates grant a great...
Read more >Data Table Show Child Rows - StackBlitz
Starter project for Angular apps that exports to the Angular CLI. ... import { DataTableDirective } from. 'angular-datatables'; ... dtOptions: DataTables.
Read more >Integrate Data table with Angular 8 Application With JSON ...
DataTables is a plug-in for the JQuery JavaScript library. It is a highly flexible tool, build upon the foundations of progressive ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi Check this.
Here the nested datatable is part of another component and is dynamically inserted when you click on expand icon.
@alok-prasad it worked like a charm. thanks a lottt.