首页 文章

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

提问于
浏览
4

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

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

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

我试过代码 -

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

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

1 回答

  • 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
          }]
      });
    

相关问题