Search code examples
angularangular5angular-material2teradata-covalent

Expandable table rows td-datatable teradata Covalent


I have been using Teradata Covalent Datatable for my table structure needs and it has been great and simple till i needed to create an expandable table row. I have searched and found that it's possible with mat-table directly using angular material to achieve this. enter image description here

I was wondering if it's possible to archieve the same using Teradata Covalent's td-datatable.


Solution

  • Ok, after some chatting with the Teradata folks on gitter, i came up with a solution to use the toggle directive from the CovalentCommonModule and included it into a custom td-datatable i managed to comeup with something close to that.

    app.component.html

    <table td-data-table #dataTable>
      <thead>
        <tr td-data-table-column-row>
          <th td-data-table-column
              *ngFor="let column of configWidthColumns"
              [numeric]="column.numeric">
            {{column.label}}
          </th>
        </tr>
      </thead>
      <tbody *ngFor="let row of data;let i=index">
        <tr class="cursor-pointer" td-data-table-row (click)="toggle(i)">
          <td td-data-table-cell *ngFor="let column of configWidthColumns" [numeric]="column.numeric">
            {{column.format ? column.format(row[column.name]) : row[column.name]}}
          </td>
        </tr>
        <tr [tdToggle]="toggleDiv[i]">
          <td colspan="7">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
          </td>
        </tr>
      </tbody>
    </table>
    

    app.component.ts

      toggleDiv: boolean[] = [];
    
      constructor(private _dataTableService: TdDataTableService) {
        this.toggleDiv = Array(this.data.length).fill().map((e, i) => true);
      }
    
      toggle(i: any): void {
        this.toggleDiv[i] = !this.toggleDiv[i];
      }
    

    For any one who needs this you can find the full implementation on stackblitz