简体   繁体   English

我可以在垫扩展行中显示另一个表吗?

[英]Can I display another table inside mat-expanded row?

I have a mat-table with an expanded row. 我有一个带扩展行的垫子桌子。 If I click on a row it expands and displays a hardcoded string. 如果我单击一行,它将展开并显示一个硬编码的字符串。 I would like to display another table inside the expanded row. 我想在扩展行内显示另一个表。 Is it possible? 可能吗? Alternatively, is there any other technique or method to achieve what I am trying to do. 或者,是否有其他任何技术或方法可以实现我想要做的事情。 I am trying to display List of executed Jobs for a given time period. 我正在尝试显示给定时间段内已执行作业的列表。 On main row, I want to show only time period something like 01-01-2017 TO 01-05-2017 and when a user clicks on that row it will expand and display a list of jobs with other details like date, time, user, status etc.. will be displayed 在主行上,我只想显示时间段,例如01-01-2017 TO 01-05-2017,当用户单击该行时,它将展开并显示具有其他详细信息(如日期,时间,用户)的作业列表,状态等。

Code for HTML :- HTML代码:-

      <mat-table [dataSource]="jobExecutionStat">
        <!-- Id Column -->
        <ng-container matColumnDef="position">
            <mat-header-cell *matHeaderCellDef>
                Serial Number
            </mat-header-cell>
            <mat-cell *matCellDef="let element; let i = index"
                >{{ i + 1 }}
            </mat-cell>
        </ng-container>
        <!-- Execution Date Column -->
        <ng-container matColumnDef="executionDate">
            <mat-header-cell *matHeaderCellDef>
                Execution Date
            </mat-header-cell>
            <mat-cell *matCellDef="let element"
                >{{ element.executionDate | date: 'yyyy-MM-dd' }}
            </mat-cell>
        </ng-container>

        <!-- After Time Period Column -->
        <ng-container matColumnDef="afterTimePeriod">
            <mat-header-cell *matHeaderCellDef>
                Current Time Period
            </mat-header-cell>
            <mat-cell *matCellDef="let element"
                >{{ element.afterTimePeriod }}
            </mat-cell>
        </ng-container>

        <!-- Previous Time Period Column -->
        <ng-container matColumnDef="previousTimePeriod">
            <mat-header-cell *matHeaderCellDef>
                Previous Time Period
            </mat-header-cell>
            <mat-cell *matCellDef="let element"
                >{{ element.previousTimePeriod }}
            </mat-cell>
        </ng-container>
        <!-- Status Column -->
        <ng-container matColumnDef="status">
            <mat-header-cell *matHeaderCellDef> Status </mat-header-cell>
            <mat-cell *matCellDef="let element"
                >{{ element.status }}
            </mat-cell>
        </ng-container>

        <!--  Code for Stop and Re-Run Buttons -->
        <ng-container matColumnDef="actions">
            <mat-header-cell *matHeaderCellDef> </mat-header-cell>
            <mat-cell *matCellDef="let element; let index = index">
                <button
                    *ngIf="index === 0"
                    mat-icon-button
                    (click)="stop_exec_job(element)"
                    matTooltip="Stop Executing the Job"
                    [disabled]="
                        element.status == 'SUCCESS' ||
                        element.status == 'FINISH' ||
                        element.status == 'CANCELLED'
                    "
                >
                    <!-- Edit icon for row -->
                    <i class="material-icons" style="color:red"> stop </i>
                </button>
                <!-- Delete icon for row -->
                <button
                    *ngIf="index === 0"
                    mat-icon-button
                    (click)="re_run_job(element)"
                    matTooltip="Re-Run the Job"
                    [disabled]="
                        element.status == 'RUNNING' ||
                        element.status == 'Pending'
                    "
                >
                    <i class="material-icons" style="color:green">
                        cached
                    </i>
                </button>
            </mat-cell>
        </ng-container>
        <!-- Code for Spinner -->
        <ng-container matColumnDef="spinner">
            <mat-header-cell *matHeaderCellDef> </mat-header-cell>
            <mat-cell *matCellDef="let element">
                <div
                    *ngIf="
                        element.status == 'Running';
                        else doNotShowSpinner
                    "
                >
                    <mat-spinner
                        mode="indeterminate"
                        [diameter]="20"
                    ></mat-spinner>
                </div>
                <ng-template #doNotShowSpinner> </ng-template>
            </mat-cell>
        </ng-container>
        <!-- Expanded Content Column - The detail row is made up of this one column -->
        <ng-container matColumnDef="expandedDetail">
            <mat-cell *matCellDef="let detail">
                Sample Text
            </mat-cell>
        </ng-container>

        <mat-header-row
            *matHeaderRowDef="jobExecStatDisplayedColumns"
        ></mat-header-row>
        <mat-row
            *matRowDef="let row; columns: jobExecStatDisplayedColumns"
            matRipple
            class="element-row"
            [class.expanded]="expandedElement == row"
            (click)="
                expandedElement === row
                    ? (expandedElement = null)
                    : (expandedElement = row)
            "
        >
        </mat-row>
        <mat-row
            *matRowDef="
                let row;
                columns: ['expandedDetail'];
                when: isExpansionDetailRow
            "
            [@detailExpand]="
                row.element == expandedElement ? 'expanded' : 'collapsed'
            "
            style="overflow: hidden"
        >
        </mat-row>
    </mat-table>

Yes you can, check out this stackblitz. 是的,您可以,查看堆叠闪电战。

Just add another mat-table like you normally would, including a datasource, column definitions etc. 只需像往常一样添加另一个mat-table ,包括数据源,列定义等。

On important thing to note is that you need to make sure your table in the expanded row spans all columns (unless you don't want it to). 需要注意的重要一点是,您需要确保扩展行中的表跨越所有列(除非您不希望这样做)。 Set the attr.colspan attribute of the detail row to the number of columns you want to span, usually you can just take the length of your displayedColumns array to span all columns. 设置attr.colspan细节行到要跨越的列数的属性,通常你可以只取length您的displayedColumns阵列跨越所有列。

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

相关问题 如何在扩展垫行而不是主表中显示垫表 - How to show mat-table in Expanded Mat-row rather than in Main table 引导程序数据表:如果我通过AJAX获取数据,则无法在扩展行中显示数据 - Bootstrap datatables: Can't display data in expanded row if I get data by AJAX 如何在 mat-table 行中显示图标? - How to display icon in mat-table row? 有没有一种方法可以使角形材质表保持扩展状态? (带有tr和td,而不是行标记) - Is there a way how angular material table will stay expanded ? (with tr and td, not mat-row tag) 如何从一个阵列是另一个数组内检索数据,并在表中显示了吗? - How can I retrieve data from an array which is inside another array and display it in the table? 如何在另一个页面上显示刚刚被点击的表格行? - How can i display the table row that just got clicked, on another page? 创建一个带有扩展行的基本表 - Create a basic table with expanded row 如何动态在另一个表中添加表 - How can i add a table inside another table dynamically 将表中单击的行的结果绑定到另一个表中的另一行 - Binding the results of a clicked row inside a table into another row in another table 我如何内爆每一行并显示在表格上? - How can i implode each row and display on a table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM