gpt4 book ai didi

kendo-ui - Kendo Grid - 查找单击单元格的列和行索引

转载 作者:行者123 更新时间:2023-12-04 20:39:37 25 4
gpt4 key购买 nike

我有一个 Kendo UI 数据网格和属性 data-selectable="cell"。我想要

1)捕获任何单元格被点击的事件 - 无论是从标题行还是网格中的任何其他行

2)找到该单元格的列和行的索引

我已经尝试过代码 -

Kendo UI Grid: Select single cell, get back DataItem, and prevent specific cells from being selected?

行索引适用于此代码,列不适用 - 始终返回 -1。此外,此事件在页面加载时会触发 5 次 - 不仅仅是单击单元格。

最佳答案

对于单细胞选择

http://dojo.telerik.com/@harsh/aToKe阅读更改事件的评论

代码:

$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers"
},
pageSize: 20
},
height: 300,
sortable: true,
selectable: 'cell',
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
change: function (e) {
var $grid = e.sender; //grid ref
var $cell = $grid.select(); // selected td
var $row = $cell.closest('tr'); //selected tr
var row_uid = $row.attr('data-uid'); //uid of selected row
var cell_index = $cell.index(); //cell index 0 based
var row_index = $row.index(); //row index 0 based
var row_data = $grid.dataItem($row).toJSON(); //selected row data

console.log(row_data);
},
columns: [{
field: "ContactName",
title: "Contact Name",
width: 200
}, {
field: "ContactTitle",
title: "Contact Title"
}, {
field: "CompanyName",
title: "Company Name"
}, {
field: "Country",
width: 150
}]
});

关于kendo-ui - Kendo Grid - 查找单击单元格的列和行索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28860778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com