[英]How do I get a row data selecting a singles cell on kendo UI MVC grid?
我使用Kendo網格來表示一個年度計划,其中每個人一行,一個列有員工姓名的列,網格上顯示的是當月的另一天30/31。 我需要的是選擇一個單元格,獲取員工姓名(或ID)和索引。
這是網格代碼:
@(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);}
...還有更多...網格可以按單元格選擇(不行)
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple)
.Type(GridSelectionType.Cell))
並且我需要使用JavaScript訪問數據項,到目前為止,這就是我得到的全部信息:
function getDataFromGrid(gridName){
var grid = $('#'+gridName).data('kendoGrid');
alert(grid);
var cell = grid.select();
使用
var data = grid.dataItem(cell);
除非可以按行(不是單元格)選擇,否則它將無法工作。
先感謝您
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可以使用jQuery和click事件瀏覽網格嗎? 類似於以下內容。
$('#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.