Reputation: 1585
I have a nested Telerik Grid within another Telerik Grid and I want to force the grid to refresh itself upon every expand of the parent grid. The data within the nested grid can change rapitly and therefore I need the nested grid to refresh itself upon every expand event.
My Telerik Grid:
<div>
@(Html.Telerik().Grid<RentableUnit>()
.Name("RentableUnits")
.Columns(columns =>
{
columns.Bound(e => e.UnitID).Hidden();
columns.Bound(e => e.Name).Width(800);
columns.Bound(e => e.IsExpanded).Hidden();
})
.ClientEvents(events => events.OnRowDataBound("employees_onRowDataBound")
.OnDetailViewExpand("unit_onDetailViewExpand")
.OnDetailViewCollapse("unit_onDetailViewCollapse")
.OnDetailViewExpand("toggleDetail")
)
.DetailView(details => details.ClientTemplate(
//stuff in template
)
.DataBinding(dataBinding => dataBinding.Ajax().Select("RentableUnits", "Home"))
.Sortable()
)
</div>
My Javascript:
function unit_onDetailViewExpand(e) {
var mstRow = e.masterRow;
var unitNumber = mstRow.cells[1].innerHTML;
var grid = $(this).data('tGrid');
grid.$rows().not(e.masterRow).each(function(index, row) {
grid.collapseRow(row);
});
//I´ve been trying to force databinding on the grid row
grid.expandRow(e.row);
//I´ve been trying this among others but I´m missing something
}
Can anyone point me in the right direction on how to force the gridrow rebind? Any help is very much appreciated :)
Upvotes: 0
Views: 1333
Reputation: 20193
This way you rebind all the Grids on the page. To refresh only the Grid which is inside of the detail row you can use the following logic inside of the DetailExpand event to find the Grid get its client object and use the ajaxRequest method.
function unit_onDetailViewExpand(e){
$(e.detailRow).find('.t-grid').data().tGrid.ajaxRequest();
}
Upvotes: 1
Reputation: 1585
I spoke to soon, just after I posted this question the answer hit me (for some odd reason). I managed to force the grid refresh with this loop:
for (var i = 0; i < 6; i++) {
$('#' + i + 'UnitPeriod_' + unitNumber + ' .t-refresh').trigger('click');
}
I replaced this line grid.expandRow(e.row) with the loop above. Thanx anyway :)
Upvotes: 0