我正在试着为垫子桌子做内联编辑. 我在第1页中沿着链接https://stackblitz.com/edit/angular-custom-pagination-mat-table?file=src%2Fmain.ts编辑第二行(编辑符号图标已更改),但没有保存正在移动到下一页的更改.在下一页中,第二行显示LIKE SAVE图标(出现在第1页).

Page 1, 2nd Row: enter image description here

Page 2, 2nd Row: enter image description here

我try 使用分页来更新索引列,但不起作用. {{this.paginator.pageIndex*this.paginator.pageSize+i}}.

<ng-container matColumnDef="name">
          <th mat-header-cell *matHeaderCellDef>Name</th>
          <td
            mat-cell
            *matCellDef="let element; let i = index"
            [formGroup]="element"
          >
            <!-- <span [hidden]="VOForm.get('VORows').value[i].isEditable"> -->
            <mat-form-field
              style="width: 70px"
              [appearance]="VOForm.get('VORows').value[i].isEditable? 'none' : 'legacy'"
            >
              <input
                matInput
                type="text"
                formControlName="name"
                [readonly]="VOForm.get('VORows').value[i].isEditable"
              />
            </mat-form-field>
            <!-- </span> -->
          </td>
        </ng-container>

假设i=dataIndex不起作用.

请分享工作的解决方案,因为这个堆栈闪电战链接是完全相同的东西我需要.

推荐答案

为了获得当前的编辑索引,我们可以使用下面的逻辑来做同样的事情,在相同的Stackblitz上更新!

const foundIndex = (
  this.VOForm.get('VORows') as FormArray
).controls.findIndex((item: any) => item === element);
if (foundIndex > -1) {
  alert(foundIndex);
}

我们可以使用下面的代码来触发将所有表单数组行的isEditable控件设置为true!在pagination change event!期间

...
this.paginator.page.subscribe(() => {
  (this.VOForm.get('VORows') as FormArray).controls.forEach((row) => {
    console.log(row);
    row.get('isEditable').patchValue(true);
  });
  ...

stackblitz

我们需要在页面的 Select 上做相同的逻辑,做一个过滤器,添加一个新的行,所有其他后续事件!

Angular相关问答推荐

如何将CDkDropList与Angular FormArray和FormGroup一起使用?

Angular 动画—淡出适用于DIV,不完全适用于子组件

声明Angular material 中按钮的自定义 colored颜色

路由在全局导航中总是给我/甚至使用相对路径

RxJS轮询+使用退避策略重试

如何将表单作为Angular 分量输入传递?

RXJS拆分返回值,多次调用后重新加入

Aws 代码部署在 BeforeBlockTraffic 步骤失败,即使在更新策略后也会超时

将数组传递给 URLSearchParams,同时使用 http 调用获取请求

在 Angular2 中跟踪 Google Analytics 页面浏览量

无法绑定到matDatepicker,因为它不是 input的已知属性

在同一个组件中使用 MatSort 的多个 mat-table

由router-outlet 创建时如何将css类应用于组件元素?

如何以Angular 获取嵌套表单组的控件

MatToolbar 与 Angular 9 一起使用时抛出错误

从 angular2 模板调用静态函数

在 Angular 组件模板中添加脚本标签

安装特定版本的 ng cli

Lint 错误:实现生命周期挂钩接口

Angular ngClass 和单击事件以切换类