Hello!
I have this grid. When i edit a row, i need to click 2x for select it and edit it.
I need to do the same when i click on the edit button. I need to select the row with the clicked button, but i don't know how to do it.
I try to use grid. selectRow(id), but it doesn't work.
Here is my html code:
Here is button method:
When i use grid.selectRows, it works and i can save my data in my backend:
App.component.ts
import { Component, OnInit, ViewChild } from '@angular/core';
import { EditSettingsModel, ToolbarItems, GridComponent } from '@syncfusion/ej2-angular-grids';
import { MouseEventArgs } from '@syncfusion/ej2-base';
import { data } from './datasource';
@Component({
selector: 'app-root',
template: `<ejs-grid #grid [dataSource]='data' [editSettings]='editSettings' [toolbar]='toolbar' allowPaging='true' (load)='load($event)'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=100 isPrimaryKey='true'></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=120></e-column>
<e-column field='Freight' headerText='Freight' textAlign= 'Right' width=120 format= 'C2'></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width=150></e-column>
</e-columns>
</ejs-grid>`
})
export class AppComponent implements OnInit {
public data: object[];
public toolbar: ToolbarItems[];
@ViewChild('grid')
public grid: GridComponent;
public editSettings: EditSettingsModel;
ngOnInit(): void {
this.data = data;
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' };
this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
}
load(args){
this.grid.element.addEventListener('mouseup', (e: MouseEventArgs) => {
if ((e.target as HTMLElement).classList.contains("e-rowcell")) {
if (this.grid.isEdit)
this.grid.endEdit();
let index: number = parseInt((e.target as HTMLElement).getAttribute("Index"));
this.grid.selectRow(index);
this.grid.startEdit();
};
});
}
} |
App.component.ts
import { Component, OnInit, ViewChild } from '@angular/core';
import { EditSettingsModel, ToolbarItems, GridComponent } from '@syncfusion/ej2-angular-grids';
import { MouseEventArgs } from '@syncfusion/ej2-base';
import { data } from './datasource';
@Component({
selector: 'app-root',
template: `<ejs-grid #grid [dataSource]='data' [editSettings]='editSettings' [toolbar]='toolbar' allowPaging='true' (load)='load($event)'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=100 isPrimaryKey='true'></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=120></e-column>
<e-column field='Freight' headerText='Freight' textAlign= 'Right' width=120 format= 'C2'></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width=150></e-column>
</e-columns>
</ejs-grid>`
})
export class AppComponent implements OnInit {
public data: object[];
public toolbar: ToolbarItems[];
@ViewChild('grid')
public grid: GridComponent;
public editSettings: EditSettingsModel;
ngOnInit(): void {
this.data = data;
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' };
this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
}
load(args){
this.grid.element.addEventListener('mouseup', (e: MouseEventArgs) => {
if ((e.target as HTMLElement).classList.contains("e-rowcell")) {
if (this.grid.isEdit)
this.grid.endEdit();
let index: number = parseInt((e.target as HTMLElement).getAttribute("Index"));
this.grid.selectRow(index);
this.grid.startEdit();
};
});
}
} |