Angular DevExtreme Datagrid:如何获取行的值

时间:2018-09-10 17:37:39

标签: javascript angular devexpress devextreme devextreme-angular

我有此datagrid,这是我的模板

    <dxo-paging [enabled]="true"></dxo-paging>
    <dxo-editing
      mode="row"
      [allowUpdating]="true"
      [allowDeleting]="true"
      [allowAdding]="true">
    </dxo-editing>

    <dxi-column dataField="Cuid" caption="Cuid" [width]="130"></dxi-column>
    <dxi-column dataField="Nom" caption="Nom"></dxi-column>
    <dxi-column dataField="Prenom" caption="Prenom"></dxi-column>
    <dxi-column
      dataField="EdoID"
      caption="Edo"
      [width]="125"
      [setCellValue]="preSelectEdo">
      <dxo-lookup
        [dataSource]="edos"
        displayExpr="Code"
        valueExpr="ID">
      </dxo-lookup>
    </dxi-column>

    <dxi-column
      dataField="ShopID"
      caption="Boutique"
      [width]="125"
      [setCellValue]="preSelectShop">
      <dxo-lookup
        [dataSource]="shops"
        displayExpr="Name"
        valueExpr="ID">
      </dxo-lookup>
    </dxi-column>
  </dx-data-grid>

我想获得对我的数据网格的引用,并在单击按钮内获得一个行值:

在我的 component.ts 中,我已经尝试过:

export class myComp {
constructor(){}
  @ViewChild(DxDataGridComponent) dataGrid: DxDataGridComponent;

  getValueCell(rowIndex, datafield) {
    this.dataGrid.instance.cellValue(rowIndex, datafield);
  }

  onClickBtn(){
    result = this.getValueCell(1,'Name');
    console.log(result);
  }
}

如您所见,单击时:我得到了结果'undefined';似乎我没有正确引用 datagrid

建议?

0 个答案:

没有答案