Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角2反应阵列的剑道网格_Angular_Kendo Ui_Kendo Grid_Kendo Ui Angular2 - Fatal编程技术网

Angular 角2反应阵列的剑道网格

Angular 角2反应阵列的剑道网格,angular,kendo-ui,kendo-grid,kendo-ui-angular2,Angular,Kendo Ui,Kendo Grid,Kendo Ui Angular2,在剑道网格示例中,我没有找到一个好的、简单且透明的示例,其中剑道网格作为formArray,数组的每一行作为formgroup,每个单元格作为formcontrol 在另一个问题中有一个答案,但它不是那么透明 我不能让那些标签工作 <form [formGroup]="formGroup"><kendo-grid #grid [data]="gridData" [formArray]="formArray" formArrayName="arrayGrid"

在剑道网格示例中,我没有找到一个好的、简单且透明的示例,其中剑道网格作为formArray,数组的每一行作为formgroup,每个单元格作为formcontrol

在另一个问题中有一个答案,但它不是那么透明

我不能让那些标签工作

  <form [formGroup]="formGroup"><kendo-grid
  #grid
  [data]="gridData" [formArray]="formArray" formArrayName="arrayGrid" 
  //[formGroup]="gridRow"// how to say each row is in this form group
  [height]="410"
  >
    <ng-template kendoGridToolbarTemplate>
      <button *ngIf="!isEditMode" (click)="editHandler()" class="k-button k-primary">Edit</button>
      <button *ngIf="isEditMode" (click)="saveHandler()" [disabled]="!canSave()" class="k-button">Update</button>
      <button *ngIf="isEditMode" (click)="cancelHandler()" class="k-button">Cancel</button>
    </ng-template>
    <kendo-grid-column field="ProductName" formControlName="ProductName"  title="Name" width="200">
    </kendo-grid-column>
    <kendo-grid-column field="UnitPrice" formControlName="UnitPrice" title="Price" format="{0:c}" width="80" editor="numeric">
    </kendo-grid-column>
    <kendo-grid-column field="UnitsInStock" formControlName="UnitsInStock" title="In stock" width="80" editor="numeric">
    </kendo-grid-column>
</kendo-grid></form>

编辑
更新
取消

有人做过这种实现吗?

我已经找到了解决方案。虽然有点粗糙,但效果很好。您必须使用网格的每个单元格模板中的
ng容器
,将每个剑道网格数据项作为
FormGroup
处理到
FormArray
中。在我的例子中,我从外部服务请求数据,但如果您在本地拥有数据,则几乎是相同的。 这个
FormArray
也可以在一个更大的
FormGroup
中,但为了简单起见,我把它作为一个属性

parent.component.html
你已经看过了吗?这不完全是您想要实现的,但我想是相关的。谢谢,但我们的想法是使用表格标题保存整个表格,而不是在编辑表格时逐行保存,因为我想作为一个整体进行验证。@LuizBicalho您找到答案了吗?没有,我没有找到任何答案,我创建了一个表,在这种情况下没有使用剑道网格,我想更深入地讨论这个问题,但没有时间在剑道中有一个指向此的功能请求,向上投票是有用的
<kendo-grid #grid [data]="gridData">
<kendo-grid-column field="firstField" title="ID" width="150">
  <ng-template kendoGridHeaderTemplate>
    <span>First Field</span>
  </ng-template>
  <ng-template kendoGridCellTemplate let-dataItem>
    <ng-container [formGroup]="dataItem">
      <app-my-component formControlName="firstField"></app-my-component>
    </ng-container>
  </ng-template>
</kendo-grid-column>
<kendo-grid-column field="secondField" width="145">
  <ng-template kendoGridHeaderTemplate>
    <span>Second Field</span>
  </ng-template>
  <ng-template kendoGridCellTemplate let-dataItem>
    <ng-container [formGroup]="dataItem">
      <kendo-dropdownlist formControlName="secondField" [valueField]="'id'" [textField]="'text'"></kendo-dropdownlist>
    </ng-container>
  </ng-template>
</kendo-grid-column>
import { Component, OnInit, ViewChild } from '@angular/core';
import { GridComponent, GridDataResult } from '@progress/kendo-angular-grid';
import { FormGroup, FormArray, FormBuilder } from '@angular/forms';

 export class ParentComponent implements OnInit {

 @ViewChild(GridComponent) private grid: GridComponent;
  public formArray = this.formBuilder.array([]);
  public gridData: GridDataResult;

  constructor(
    private formBuilder: FormBuilder,
    private service: MyService) {

    super();
  }

  ngOnInit() {
    this.requestData();
  }

  public requestData() {
    const response = this.service.getData().subscribe(data => {
      const that = this;
      response.forEach(function (data, i) {
        that.formArray.insert(i, that.createDataFormGroup(data));
      });

      this.gridData = {
        data: this.formArray.controls,
        total: this.formArray.controls.length
      };
    });
  }