This example shows how to implement related grids. The first grid is bound to the Customers table from the Northwind database. The second shows the orders for the selected customer from the first grid.
This example is implemented by using the OnRowSelected client-side event. In order to enable client-side selection
the Selectable() method should be used when configuring the grid.
<%= Html.Telerik().Grid((IEnumerable<Customer>)ViewData["Customers"])
.Name("Customers")
.Columns(columns =>
{
columns.Bound(c => c.CustomerID).Width(130);
columns.Bound(c => c.CompanyName).Width(250);
columns.Bound(c => c.ContactName);
columns.Bound(c => c.Country).Width(200);
})
.Pageable()
.Sortable()
.Selectable()
.ClientEvents(events => events.OnRowSelected("onRowSelected"))
.DataBinding(dataBinding => dataBinding
.Ajax()
.Select("_SelectionClientSide_Customers", "Grid"))
%>
<%= Html.Telerik().Grid((IEnumerable<Order>)ViewData["Orders"])
.Name("Orders")
.Columns(columns=>
{
columns.Bound(c => c.OrderID).Width(100);
columns.Bound(c => c.OrderDate).Width(200).Format("{0:dd/MM/yyyy}");
columns.Bound(c => c.ShipAddress);
columns.Bound(c => c.ShipCity).Width(200);
})
.Pageable()
.Sortable()
.DataBinding(dataBinding => dataBinding
.Ajax()
.Select("_SelectionClientSide_Orders", "Grid", new { customerID = "ALFKI" }))
%>
<script type="text/javascript">
function onRowSelected(e) {
var ordersGrid = $('#Orders').data('tGrid');
customerID = e.row.cells[0].innerHTML;
// update ui text
$('#customerID').text(customerID);
// rebind the related grid
ordersGrid.rebind({
customerID: customerID
});
}
</script>