我试图弄清楚如何将单击事件处理程序添加到kendo网格单元中。
这是我的代码:
<ng-template kendoGridCellTemplate let-dataItem let-rowIndex="rowIndex">
<div class="w-100 timeline-cell-container">
<ng-container *ngFor="let item of getTimelineField(parentColumn.field, dataItem, true); let i=index">
<div class="timeline-cell position-absolute" [ngStyle]="getTimelineCellStyle(item)">
{{ item.value }}
</div>
</ng-container>
</div>
</ng-template>我知道可以将onclick事件添加到内部div中,但是有方法将其附加到单元格本身吗?
我见过https://www.telerik.com/kendo-angular-ui/components/grid/api/CellClickEvent/,但不知道如何使用它,或者这是否是正确的使用方法?以下是我填充单元格信息的方式:
const buildObj = {
value: [jobObject.job],
type: 'cell',
startFrom: this.calcTimelineJobStart(startDate, index, width),
width,
color: this.colorCode(jobObject.job),
class:'hint'
};发布于 2020-10-12 18:34:31
您必须用一个<ng-template>标记包装您的<kendo-grid>标记,然后可以使用单元格单击事件发射器(cellClick)="cellClickHandler($event)。
<kendo-grid #grid (cellClick)="cellClickHandler($event)">
<ng-template kendoGridCellTemplate let-dataItem let-rowIndex="rowIndex">
<div class="w-100 timeline-cell-container">
<ng-container *ngFor="let item of getTimelineField(parentColumn.field, dataItem, true); let i=index">
<div class="timeline-cell position-absolute" [ngStyle]="getTimelineCellStyle(item)">
{{ item.value }}
</div>
</ng-container>
</div>
</ng-template>
<kendo-grid/>然后在类型记录文件中实现cellClickHandler:
public cellClickHandler({ sender, rowIndex, columnIndex, dataItem, isEdited }) {
// your code here
console.log(rowIndex, columnIndex)
}有关更多信息,请查看以下文档:链接
https://stackoverflow.com/questions/64323236
复制相似问题