0

i have this datagrid , here is my template :

    <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>

and I want to, get a reference to my datagrid and get a row value within a click button:

in my component.ts, I've tried this :

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

as you can see, when clicking: I got a result 'undefined'; it seems like I haven't got the right reference to the datagrid

Suggestions ?

Hyyan Abo Fakher
  • 3,497
  • 3
  • 21
  • 35
firasKoubaa
  • 6,439
  • 25
  • 79
  • 148

1 Answers1

0

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 + "%" : "";
        }
    }
Gülsen Keskin
  • 657
  • 7
  • 23