
|
export class AppComponent {
@ViewChild("normalgrid")
public grid: GridComponent;
public data: Object[];
public editSettings: Object;
public editparams: Object;
public flag: boolean;
public formatoptions: Object;
public mouseTimer;
public ele;
public gfields = ["OrderID", "CustomerID", "ShipCity", "ShipCountry"];
public rowIndex;
public field;
public ngOnInit(): void {
this.data = orderDataSource.slice(0, 30);
this.editSettings = {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: "Batch",
showConfirmDialog: false
};
this.editparams = {
params: {
dataBound: this.ddDataBound.bind(this),
change: this.change.bind(this)
}
};
this.formatoptions = { type: "dateTime", format: "M/d/y hh:mm a" };
}
load(args: any): void {
this.grid.element.addEventListener("mousedown", this.mouseDown.bind(this)); // mouseDown event
this.grid.element.addEventListener("mouseup", this.mouseUp.bind(this)); //mouseUp event
}
ddDataBound(args) {
var drop = document.getElementsByClassName("e-dropdownlist")[0]
.ej2_instances[0];
drop.showPopup(); // open dropdown popup initially.
}
change(args) {
//triggered when the dropdown value changed
this.grid.saveCell(); // save the changed value
this.grid.endEdit(); // update the selected value
}
cellEdit(args) {
if (this.flag == true) {
args.cancel = true; // prevent the edit action
this.flag = false; // set the flag as false
}
}
recordDoubleClick() {
// triggered when double click the record
this.flag = true; // set the flag variable as true
}
mouseDown(args) {
debugger;
if (args.target.getAttribute("class") == "e-rowcell") {
this.ele = args.target;
this.mouseUp();
this.rowIndex = parseInt(args.target.getAttribute("index"));
this.field = this.gfields[
parseInt(args.target.getAttribute("aria-colindex"))
];
this.mouseTimer = window.setTimeout(this.menu_toggle.bind(this), 2000); //set timeout to fire in 2 seconds when the user presses mouse button down
}
}
menu_toggle() {
this.grid.editCell(this.rowIndex, this.field); // edit the target cell by passing rowIndex and field values as parameter to editCell method.
}
mouseUp() {
if (this.mouseTimer) window.clearTimeout(this.mouseTimer); //cancel timer when mouse button is released
}
} |
|
<ejs-grid #normalgrid id="Normalgrid" [dataSource]="data" allowPaging="true" [editSettings]="editSettings"
(load)="load($event)" (recordDoubleClick)="recordDoubleClick($event)" (cellEdit)="cellEdit($event)">
<e-columns>
<e-column field="OrderID" headerText="Order ID" width="140" textAlign="Right" isPrimaryKey="true">
</e-column>
<e-column field="CustomerID" headerText="Customer ID" width="150" editType="dropdownedit"
[edit]="editparams"></e-column>
<e-column field="ShipCity" headerText="Ship City" width="150" editType="dropdownedit"
[edit]="editparams"></e-column>
<e-column field="ShipCountry" headerText="Ship Country" width="150" editType="dropdownedit"
[edit]="editparams"></e-column>
</e-columns>
</ejs-grid> |
|
export class AppComponent {
@ViewChild("normalgrid")
public grid: GridComponent;
public data: Object[];
public editSettings: Object;
public editparams: Object;
public flag: boolean;
public formatoptions: Object;
public mouseTimer;
public ele;
public gfields = ["OrderID", "CustomerID", "ShipCity", "ShipCountry"];
public rowIndex;
public field;
public ngOnInit(): void {
this.data = orderDataSource.slice(0, 30);
this.editSettings = {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: "Batch",
showConfirmDialog: false
};
this.editparams = {
params: {
dataBound: this.ddDataBound.bind(this),
change: this.change.bind(this),
open: this.OnOpen.bind(this)
}
};
this.formatoptions = { type: "dateTime", format: "M/d/y hh:mm a" };
}
load(args: any): void {
this.grid.element.addEventListener("mousedown", this.mouseDown.bind(this)); // mouseDown event
this.grid.element.addEventListener("mouseup", this.mouseUp.bind(this)); //mouseUp event
}
ddDataBound(args) {
var drop = document.getElementsByClassName("e-dropdownlist")[0]
.ej2_instances[0];
drop.showPopup(); // open dropdown popup initially.
}
change(args) {
//triggered when the dropdown value changed
this.grid.saveCell(); // save the changed value
this.grid.endEdit(); // update the selected value
}
OnOpen(e, instance) { // dropdown popup open event
var drop = document.getElementsByClassName("e-dropdownlist")[0]
.ej2_instances[0];
e.popup.element
.querySelector("ul")
.addEventListener("mouseup", function(e) {
drop.onMouseClick(e); // here we select the hover dropdown item by mouseUp event
});
}
cellEdit(args) {
if (this.flag == true) {
args.cancel = true; // prevent the edit action
this.flag = false; // set the flag as false
}
}
recordDoubleClick() {
// triggered when double click the record
this.flag = true; // set the flag variable as true
}
mouseDown(args) {
if (args.target.classList.contains("e-rowcell")) {
this.ele = args.target;
this.mouseUp();
this.rowIndex = parseInt(args.target.getAttribute("index"));
this.field = this.gfields[
parseInt(args.target.getAttribute("aria-colindex"))
];
this.mouseTimer = window.setTimeout(this.menu_toggle.bind(this), 2000); //set timeout to fire in 2 seconds when the user presses mouse button down
}
}
menu_toggle() {
this.grid.editCell(this.rowIndex, this.field); // edit the target cell by passing rowIndex and field values as parameter to editCell method.
}
mouseUp() {
if (this.mouseTimer) window.clearTimeout(this.mouseTimer); //cancel timer when mouse button is released
}
} |
|
<ejs-grid #normalgrid id="Normalgrid" [dataSource]="data" allowPaging="true" [editSettings]="editSettings"
(load)="load($event)" (recordDoubleClick)="recordDoubleClick($event)" (cellEdit)="cellEdit($event)">
<e-columns>
<e-column field="OrderID" headerText="Order ID" width="140" textAlign="Right" isPrimaryKey="true">
</e-column>
<e-column field="CustomerID" headerText="Customer ID" width="150" editType="dropdownedit"
[edit]="editparams"></e-column>
<e-column field="ShipCity" headerText="Ship City" width="150" editType="dropdownedit"
[edit]="editparams"></e-column>
<e-column field="ShipCountry" headerText="Ship Country" width="150" editType="dropdownedit"
[edit]="editparams"></e-column>
</e-columns>
</ejs-grid> |
|
load(args: any): void {
this.grid.element.addEventListener("mousedown", this.mouseDown.bind(this)); // mouseDown event
this.grid.element.addEventListener("mouseup", this.mouseUp.bind(this)); //mouseUp event
for (var i = 0; i < this.grid.columns.length; i++) {
(this.grid.columns[i] as any).edit = this.editparams;
}
}
|