首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将单击事件添加到kendoGridCellTemplate

如何将单击事件添加到kendoGridCellTemplate
EN

Stack Overflow用户
提问于 2020-10-12 18:15:04
回答 1查看 1.9K关注 0票数 1

我试图弄清楚如何将单击事件处理程序添加到kendo网格单元中。

这是我的代码:

代码语言:javascript
复制
<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/,但不知道如何使用它,或者这是否是正确的使用方法?以下是我填充单元格信息的方式:

代码语言:javascript
复制
const buildObj = {
          value: [jobObject.job],
          type: 'cell',
          startFrom: this.calcTimelineJobStart(startDate, index, width),
          width,
          color: this.colorCode(jobObject.job),
          class:'hint'
        };
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-12 18:34:31

您必须用一个<ng-template>标记包装您的<kendo-grid>标记,然后可以使用单元格单击事件发射器(cellClick)="cellClickHandler($event)

代码语言:javascript
复制
<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

代码语言:javascript
复制
public cellClickHandler({ sender, rowIndex, columnIndex, dataItem, isEdited }) {
  // your code here
  console.log(rowIndex, columnIndex)
}

有关更多信息,请查看以下文档:链接

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64323236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档