Hello, I am struggling to figure out how to get a count of how many rows are in each of my kendo grid groups in the DataBound method. I can't find anything on this. My grid is pretty simple, and it is grouped by a single column (tran_code).
The grouping works fine but I cannot figure out how to hide the group header row altogether if there is only 1 row in that group, otherwise show it. All I have so far is my grouping, which is working. I am using @html helper for the grid:
@(Html.Kendo().Grid(CarryFwdDetail)
.Name("grid")
.Group(groups => groups.Add(p => p.TranCode))
In a javascript function how can I access the group rows and count them (for each group), then hide that group header?
Any help is appreciated!
Thanks, Justin
Update:
I an effort to provide as much code as possible, I have been able to get to a point where I can get the count groups there are. But I still don't know how to get the count of rows within each group and hide that groups header if it is = 1:
.Events(e=>e.DataBound(@<text>function(e){
var view = this.dataSource.view();
if(this.dataSource.group())
{
var count = 0;
eachGroupItems(view, function(items, index)
{
count++
alert(count);
});
}
}</text>))
function eachGroupItems(data, func) { for (var idx = 0, length = data.length; idx < length; idx++) { if (data[idx].hasSubgroups) { if (eachGroupItems(data[idx].items, func)) { return true; } } else if (func(data[idx].items, data[idx])) { return true; } } }
Update 2
I have now figured out how to get the count of rows within each grouping:
function eachGroupItems(data, func) { for (var i = 0, length = data.length; i < length; i++) { alert("Data length: " + data[i].items.length); //= number of rows in each group if(data[i].items.length == 1) { } } }
Can anybody help me with how to hide the group header row?
Update 3
I figured it out. Here is the new javascript function to replace eachGroupItems()
function eachGroupItems(data, func) {
for (var i = 0, length = data.length; i < length; i++)
{
//alert("Data length: " + data[i].items.length); //= number of rows in each group
if(data[i].items.length == 1)
{
$('#grid tbody .k-grouping-row').hide();
}
}
}
Hopefully this helps somebody in the future...
Thanks