Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a grouped Kendo Grid collapsible by default?

Here is what I have so far:

 $(reportTableSelector).kendoGrid({
    dataSource: dataSource,
    sortable: false,
    pageable: false,
    scrollable: false,
    columns: colModel
});

var grid = $(reportTableSelector).data("kendoGrid");
grid.collapseGroup(grid.tbody.find(">tr.k-grouping-row"));
$('tr[role*="row"]').hide();

If I put the last three lines of code in a click handler function, it will effectively collapse all the grouped rows but not when calling it after initializing the grid.

like image 489
JamesRLamar Avatar asked Dec 04 '22 13:12

JamesRLamar


1 Answers

A more idiomatic way of doing it

var collapseAllGroups = function (grid) {
    grid.table.find(".k-grouping-row").each(function () {
        grid.collapseGroup(this);
    });
}

//On the grid
dataBound: function (e) {
    collapseAllGroups(this);
}
like image 148
leojh Avatar answered Jan 12 '23 01:01

leojh