折叠剑道网格中的特定组

时间:2019-03-21 14:23:38

标签: javascript jquery kendo-ui

问题:我有一个包含3层分组的kendo网格。我希望第一小组扩大,而第二和第三小组崩溃。我尝试了几种不同的方法,但似乎无法完成这项工作。

@(Html.Kendo().Grid<OfferViewModel>()
                    .Name("grid")
                    .Selectable()
                    .Sortable(sort => sort.AllowUnsort(true).SortMode(GridSortMode.MultipleColumn))
                    .Filterable(filterable => filterable.Extra(false))
                    .Scrollable(s => s.Enabled(true))
                    .Reorderable(reorder => reorder.Columns(true))
                    .Resizable(resize => resize.Columns(true))
                    .Columns(c =>
                    {
                        ...;
                    })
                .Events(e => e.DataBound("OffersDataBound").ExcelExport("OffersExcelExport"))
                .NoRecords(n => n.Template("<br><b><font color='red'>NO RECORDS FOUND</font></b>"))
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(20)
                    .ServerOperation(true)
                    .Aggregates(agg =>
                    {
                        agg.Add(a => a.CrewsOffered).Sum();
                        agg.Add(a => a.RequestCrewsRequested).Sum();
                        agg.Add(a => a.ResourceTypeName).Count();
                        agg.Add(a => a.RequestRestorationEventName).Count();
                    })
                    .Group(grp =>
                    {
                        grp.Add(g => g.RequestRestorationEventName);
                        grp.Add(g => g.ResourceTypeName);
                        grp.Add(g => g.RequestSourceShortName);

                    })
                    .Read(read => read.Action("ReadEventOffers", "Offers", new { id = @Model.RequestRestorationEventId }))
                    ...
                )
            )

function OffersDataBound() {
        resizeOffersGrid();
        attachToolTipsToCells('grid');
        collapseAllGroups('grid');
    }

var collapseAllGroups = function (grid) {
        //RequestSourceShortName
        var grid = $("#grid").data("kendoGrid");
        var dataView = grid.dataSource.view();

        for (var i = 0; i < dataView.length; i++) {
            for (var j = 0; j < dataView[i].items.length; j++) {
                var test = dataView[i].items[j];
                for (var k = 0; k < test.items.length; k++) {
                    var test2 = test.items[k]
                    if (test2.field == "RequestSourceShortName") {
                        var uid = test2.uid;

                        //var temp = $("#grid").find("tr[data-uid=" + uid + "]")
                        //debugger
                        //grid.collapseGroup($("#grid").find("tr[data-uid=" + uid + "]").prev("tr.k-grouping-row"));

                        var el = $("#grid"),
                            grid = el.data("kendoGrid"),
                            row = el.find("tbody>tr[data-uid=" + uid + "]");
                        console.log(row); //check if the row is found
                        grid.collapseGroup(row);
                    }
                }
            }
        }
    }

我想念什么?我确实必须在应用程序的其他区域中执行此操作,并且我可能需要折叠不同的组。如果某人有一个动态的解决方案-可以应用于任何小组-那就太好了。如果没有,我不太挑剔;)

0 个答案:

没有答案