You need some little programming and knowing how to select and deselect rows...
The very first thing is creating the detailInit
method for your grid, you are probably familiar with this and the only thing here is add a little trick for easily find the details rows in the parent grid.
function detailInit(e) {
$("<div class='ob-child-grid'/>").appendTo(e.detailCell).kendoGrid({
...
});
}
As you can see, I've added the class ob-child-grid
to the container of the grid. I can actually rely on k-secondary
(this class is added by Kendo UI to this node) but I prefer not to rely on non documented functionality so the code is less vulnerable to future modifications of KendoUI.
Next is defining a change
handler that gets invoked when the row in the parent is selected. This function has to do:
- Remove previously selected rows in details grid. I'm assuming that once you select a new row in the parent you want to get the children of the previously selected parent deselected.
- Find the child grid of the currently selected row.
- Select every element in the child grid.
Lets see how to do it:
// Remove previous selections
$("tr", ".ob-child-grid").removeClass("k-state-selected");
As you can see this step is pretty simple, just remove "k-state-selected" this is all you actually need.
// Find the child grid.
var child = this.select().next().find(".ob-child-grid");
this.select()
gets currently selected row and next()
gets next row that is where KendoUI places the child grid. With find(".ob-child-grid")
we find the node where the grid actually is.
// Select every row
$("tr", child).addClass("k-state-selected");
We add k-state-selected
that is the class that marks a row as selected.
You can play with the idea here: http://jsfiddle.net/OnaBai/XaMer/