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

Par*_*rth 5 kendo-ui kendo-grid

我有一个Kendo UI数据网格,并具有data-selectable =“ cell”属性。我想要

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

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

我在以下位置尝试过该代码-

Kendo UI网格:选择单个单元格,取回DataItem,并防止选择特定的单元格?

行索引与此代码一起使用,列则无效-始终返回-1。此外,此事件在页面加载时会触发5次-不仅仅是单元格点击。

Har*_*rsh 3

用于单细胞选择

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
      }]
  });
Run Code Online (Sandbox Code Playgroud)