App.component.ts
export class AppComponent {
@ViewChild("grid", { static: false }) grid: GridComponent;
public data: Object[];
public flag: boolean = true;
public selectOptions: Object;
public editSettings: Object;
public toolbar: string[];
public pageSettings: any = { pageSize: 6 };
allChecked = {
all: false,
indeterminate: false
};
public ngOnInit(): void {
this.data = orderDetails.map((order, index) => {
return { ...order, id: index, checked: false };
});
}
onCheckedRowToggle(args, row: Object) {
const { checked } = args;
this.setCheckedStateToRow(row, checked);
this.emitCheckedRows();
this.setCheckRowHeaderState(<Object[]>this.grid.dataSource);
}
dataBound(args) {
if (this.flag) {
this.grid.keyboardModule.keyConfigs["enter"] = "";
this.flag = false;
}
}
public keyHandler(e) {
if (e.altKey) {
if (e.keyCode === 67) {
var ele = parentsUntil(e.target, "e-row", false);
if (ele) {
let cbox = ele.querySelector(".e-checkbox").ej2_instances[0];
cbox.checked = !cbox.checked;
}
}
if (e.keyCode === 65) {
var ele = parentsUntil(e.target, "e-row", false);
if (ele) {
(ele.querySelector(".e-templatecls") as any).click();
}
}
}
if (e.keyCode === 13) {
if (e.target.classList.contains("e-checkbox")) {
let cbox = e.target.ej2_instances[0];
cbox.checked = !cbox.checked;
}
if (e.target.classList.contains(".e-templatecls")) {
e.target.click();
}
}
}
onCheckHeaderToggle(args) {
const { checked } = args;
const dataSource = <Object[]>this.grid.dataSource;
dataSource.forEach(row => {
this.setCheckedStateToRow(row, checked);
row["checked"] = checked;
});
this.emitCheckedRows();
this.setCheckRowHeaderState(<Object[]>this.grid.dataSource);
}
private setCheckedStateToRow(row, checked) {
const index = this.grid.getRowIndexByPrimaryKey(row["id"]);
this.grid.setCellValue(row["id"], "checked", checked);
//this.grid.updateCell(index, "checked", checked);
}
private emitCheckedRows() {
const dataSource = <Object[]>this.grid.dataSource;
const checkedRows = dataSource.filter(rows => rows["checked"]);
//this.onCheckRow.emit(checkedRows);
console.log("CHEKED ROWS", checkedRows);
}
private setCheckRowHeaderState(rows: Object[]) {
const checkedRows = rows.filter(rows => rows["checked"]);
if (checkedRows.length === 0) {
this.allChecked = {
all: false,
indeterminate: false
};
} else {
if (checkedRows.length === this.data.length) {
this.allChecked = {
all: true,
indeterminate: false
};
} else {
this.allChecked = {
all: false,
indeterminate: true
};
}
}
}
handleAnchor(args) {
console.log("ARGS", args);
}
} |