【问题标题】:Kendo Grid - find column and row index of clicked cellKendo Grid - 查找单击单元格的列和行索引
【发布时间】:2015-05-05 19:32:56
【问题描述】:

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

【问题讨论】:

  • 可能会尝试在你工作/当前拥有的东西上添加一些相关代码,一个 jsfiddle 或一个代码 sn-p,这样你就可以缩小罪魁祸首列表
  • @Parth 你只需要单击单个单元格吗???
  • 你应该添加你自己的代码

标签: kendo-ui kendo-grid


【解决方案1】:

对于单个单元格选择

http://dojo.telerik.com/@harsh/aToKe 读取 cmets 以获取更改事件

代码:

$("#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
      }]
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 2015-09-21
    • 1970-01-01
    相关资源
    最近更新 更多