简体   繁体   English

如何选择Kendo UI网格的不同细节模板

[英]How to select different detail templates of a kendo ui grid

I have a kendo grid detail template like this example: http://demos.telerik.com/aspnet-mvc/grid/detailtemplate , and i want to select the different details of every master grid at once, but i only can select one detail template of a master grid. 我有一个类似此示例的kendo网格细节模板: http : //demos.telerik.com/aspnet-mvc/grid/detailtemplate ,我想一次选择每个主网格的不同细节,但是我只能选择一个主网格的详细信息模板。

I need to get all the rows selected of every different detail template of a master grid. 我需要从主网格的每个不同详细信息模板中选择所有行。 Here is the javascript code that only get the selected rows of one detail template: 以下是仅获取一个详细信息模板的选定行的javascript代码:

$('#send').click(function () {
            var items = {};
            var grid = $('.k-detail-row .k-grid').data('kendoGrid');
            var selectedElements = grid.select();
            for (var j = 0; j < selectedElements.length; j++) {
                var item = grid.dataItem(selectedElements[j]);
                items['anyName[' + j + '].CodMarca'] = item.CodMarca;
            }
            $.ajax({
                url: '@Url.Action("Index", "Busqueda")',
                type: "POST",
                async: false,
                data: items,
                success: function (result) {
                    console.log(result);
                }
            })
        })

With this part of the code i only get one detail template and no the others: 有了这部分代码,我只得到一个细节模板,而没有其他细节模板:

var grid = $('.k-detail-row .k-grid').data('kendoGrid');

I really need to select the other detail templates too. 我真的也需要选择其他详细信息模板。

You need to iterate through all the detail grids...you are only processing the first one. 您需要遍历所有细节网格...您仅在处理第一个网格。

When you do this: var grid = $('.k-detail-row .k-grid').data('kendoGrid'); 当执行此操作时: var grid = $('.k-detail-row .k-grid').data('kendoGrid'); you are just getting a reference to the first detail grid even if $('.k-detail-row .k-grid') returns more than one matching element. 即使$('.k-detail-row .k-grid')返回多个匹配元素,您也只能获得对第一个详细信息网格的引用。 This is the way jQuery works...it will return the data() of the first element of the returned array...it will not return the .data() of all the returned matches. 这就是jQuery的工作方式...它将返回返回数组的第一个元素的data()...不会返回所有返回的匹配项的.data()。

So, you have to iterate through the returned matches yourself, get the grid reference attached to the match, get the selected rows, move on to the next grid/match, ie: 因此,您必须自己遍历返回的匹配项,获取匹配项的网格引用,获取选定的行,然后转到下一个网格/匹配项,即:

var items = [];
var grids = $('.k-detail-row .k-grid');

// Loop through the grids.                
for (var i = 0; i < grids.length; i++) {
    var grid = $(grids[i]).data('kendoGrid');
    var selectedElements = grid.select();

    // Loop through the selected items of the *current* grid.
    for (var j = 0; j < selectedElements.length; j++) {
        var item = grid.dataItem(selectedElements[j]);

        items.push(item);
    }
}

// Do whatever you want with the collected items.
console.log(items);

Demo 演示版

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

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