【问题标题】:Angular DevExtreme Datagrid : how to get values of a rowAngular DevExtreme Datagrid:如何获取一行的值
【发布时间】:2018-09-10 17:37:39
【问题描述】:

我有这个数据网格,这是我的模板

    <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);
  }
}

如你所见,点击时:I got a result 'undefined';似乎我没有正确引用 datagrid

建议?

【问题讨论】:

  • return this.dataGrid.instance....?
  • @yurzui 不,不是这样
  • 试试 this.dataGrid.instance.getCellElement(rowIndex, dataField)
  • 好吧,那么如果你想获取选定行的值,你可以试试 this.dataGrid.instance.getSelectedRowsData() 并且那个方法给你选定的行,你可以解析它们.

标签: javascript angular devexpress devextreme devextreme-angular


【解决方案1】:

try this:

 onFocusedRowChanged(e) {
        var rowData = e.row && e.row.data,
            cellValue,
            assigned;

        if(rowData) {
            cellValue = e.component.cellValue(e.row.rowIndex, "Assigned");
            this.taskEmployees.byKey(cellValue).done((item) => {
                assigned = item.Name;
            });

            this.taskSubject = rowData.Task_Subject;
            this.taskAssigned = assigned;
            this.startDate = new Date(rowData.Task_Start_Date).toLocaleDateString();

            this.taskStatus = rowData.Task_Status;
            this.taskProgress = rowData.Task_Completion ? rowData.Task_Completion + "%" : "";
        }
    }

【讨论】:

    猜你喜欢
    • 2018-01-05
    • 2021-07-18
    • 2018-04-03
    • 1970-01-01
    • 2016-08-17
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多