简体   繁体   English

如何在Kendo UI MVC网格上获取选择单身人士的行数据?

[英]How do I get a row data selecting a singles cell on kendo UI MVC grid?

I'm using a kendo grid to represent an year plan where I have a line for every person and a column with the name of the employee and another 30/31 for the day of the month shown on the grid. 我使用Kendo网格来表示一个年度计划,其中每个人一行,一个列有员工姓名的列,网格上显示的是当月的另一天30/31。 What I need is by selecting one cell, getting the employee Name (or ID) and the index. 我需要的是选择一个单元格,获取员工姓名(或ID)和索引。

this is the gird code: 这是网格代码:

@(Html.Kendo().Grid<WorkTimeManager.Presentation.Models.YearPlanViewModel>()
      .Name("gridJan")

      .Columns(col =>
      {
          col.Bound(c => c.EmployeeName).Title("Employee").Width(170);
          col.Group(group => group
           .Title("January")
           .Columns(columns =>
           {
               columns.Bound(c => c.Day1).Width(30);}
               columns.Bound(c => c.Day2).Width(30);}
               columns.Bound(c => c.Day3).Width(30);}

...and some more... the grid is selectable by cell (NOT row) ...还有更多...网格可以按单元格选择(不行)

.Selectable(selectable => selectable
            .Mode(GridSelectionMode.Multiple)
            .Type(GridSelectionType.Cell))

and I need to acess the data item with JavaScript, so far this is all I got: 并且我需要使用JavaScript访问数据项,到目前为止,这就是我得到的全部信息:

function getDataFromGrid(gridName){
        var grid = $('#'+gridName).data('kendoGrid');
        alert(grid);
        var cell = grid.select();

using 使用

var data = grid.dataItem(cell);

won't work unless is selectable by row (not cell). 除非可以按行(不是单元格)选择,否则它将无法工作。

thank you in advance 先感谢您

GridSelectionMode is "Multiple" and the GridSelectionType is "Cell" the select method return array of selected grid cells GridSelectionMode是“ Multiple”,而GridSelectionType是“ Cell”,选择方法将返回选定网格单元的数组

var grid = $("#gridJan").data("kendoGrid");
currentSelection = grid.select();
selectedRows = [];
currentSelection.each(function () {
var currentRowIndex = $(this).closest("tr").index();
if (selectedRows.indexOf(currentRowIndex) == -1) {
    selectedRows.push(currentRowIndex);
}
})

@Pizzy Could you use jQuery and a click event to navigate the grid? @Pizzy可以使用jQuery和click事件浏览网格吗? Something similar to below.. 类似于以下内容。

$('#gridJan tr td').click(function(){  

   //Get the name, etc by navigating upward from td to the tr parent and then back down to find specific child td that contains the needed data
   var id = $(this).parent('tr').children('whatever you are looking for').html();

   ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM