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

时间:2015-03-04 17:19:23

标签: kendo-ui kendo-grid

我有一个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次 - 而不仅仅是单击单击。

1 个答案:

答案 0 :(得分: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
      }]
  });