首页 > 解决方案 > 鼠标向下垫表复制值

问题描述

我创建了一个带有输入的表,以介绍用户所需的列数。在这张表中,用户介绍了数据,并且为了不单独填充数百万个单元格,我想制作一个类似单元格复制粘贴的 Excel,因此,当下拉鼠标时,复制选择的第一个值,也是水平的。我想我必须制作一个 formArray 才能为表格中的每个单元格提供单独的表单控件。

我做了一个stackblitz,我试图创建一个 formArray 但只要我在表单表中引入它,它就不起作用。单元格折叠,当检查单元格内的内容时,html 文件中没有任何内容。我正在关注本教程,但无法使其正常工作。

教程

<form  name="formTable" [formGroup]="formTable">
        <table mat-table #table [dataSource]="dataSource" matTableExporter  #exporter="matTableExporter" class="mat-elevation-z8" >
            <ng-container matColumnDef="parameter">
                <mat-header-cell *matHeaderCellDef></mat-header-cell>
                <mat-cell *matCellDef="let element;" >{{element.parameter}}</mat-cell>
              </ng-container>
            <ng-container [matColumnDef]="column" *ngFor="let column of columnsToDisplay">
              <th mat-header-cell *matHeaderCellDef> {{column}} </th>
              <td mat-cell *matCellDef="let element; let i = index" (mousedown)="onMouseDown(i, column)" (mouseup)="onMouseUp(i, column)" >
                  
                  <div class="cells" *ngFor="let dataValue of dataValues().controls; let i=index">
                      <div [formGroupName]="i">
                        <mat-form-field floatLabel="never" appearance="none"  >
                            <input matInput  [value]="0" formControlName="dataValue" name="someValue" >
                          </mat-form-field>
                      </div>
                  </div>
              </td>
            </ng-container>
          
            <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
            <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
          </table>
      </form>

我使用的这段代码来自 Rakia,如果你想看看,这里是链接。可编辑表

标签: angulartypescript

解决方案


推荐阅读