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.
The example is implemented using the Action overload which supplies additional data to the action method which provides data for the grid and the rebind JavaScript method. Here is the relevant code:
<%= Html.Telerik().Grid<Order>()
.Name("Orders")
.Ajax(ajax => ajax.Action("_RelatedGrids_Orders", "Grid", new { customerID = "ALFKI" }))
.Columns(columns=>
{
columns.Add(c => c.OrderID).Width(100);
columns.Add(c => c.OrderDate).Width(200).Format("{0:dd/MM/yyyy}");
columns.Add(c => c.ShipAddress);
columns.Add(c => c.ShipCity).Width(200);
})
.Pageable()
.Sortable()
.BindTo((IEnumerable<Order>)ViewData["Orders"])
%>
<script type="text/javascript">
var ordersGrid = $('#Orders').data('tGrid');
$('#Customers tbody tr')
.live("click", function() {
// `this` == clicked row
var customerID = this.cells[0].innerHTML;
// add selected style to clicked row
$(this).addClass('t-state-selected')
.siblings()
.removeClass('t-state-selected');
// update ui text
$('#customerID').text(customerID);
// rebind the related grid
ordersGrid.rebind({
customerID: customerID
});
})
</script>