As a service to anyone trying to figure this out I'm posting my solution. This is not intuitive, nor well-documented. The sample code I've run across on many sites does not work, the objects simply are not available or something about them has been changed. IMHO, this is way harder to do than it needs to be!
In my solution, there is a three level grid. In the first and second levels I subscribe to the Expand and Databound events. There are two javascript functions for each grid. In onExpand the model id is saved to the session as this code goes away from the grid page to a view. Upon returning, onDatabound fires and the grid rows are examined until the last expanded row is found, and then expanded thus giving the user a return to the context in which they were last looking at the grid.
function onBatchGridExpand(e) {
// save the BatchID value of the row that was just expanded in the browser session
// first get the data-uid of the row
var selectedRowID = e.masterRow.closest("tr.k-master-row").attr('data-uid');
// using the uid, retrieve the BatchID value and stor it in the session
$.post('@Url.Action("SetSessionVariable", "Home")',
{
key: 'lastSelectedBatchID',
value: e.sender.dataSource.getByUid(selectedRowID).BatchID
});
}
function onBatchGridDataBound(e) {
var lastSelectedBatchID = '@Session["lastSelectedBatchID"]';
var grid = $('#BatchGrid').data("kendoGrid");
var data = grid.dataSource.data();
var totalNumber = data.length;
for (var i = 0; i < totalNumber; i++) {
var currentDataItem = data[i];
if (currentDataItem.BatchID == lastSelectedBatchID) {
var rowUID = currentDataItem.uid;
var row = grid.tbody.find("tr[data-uid='" + rowUID + "']");
grid.expandRow(row);
break;
}
}
}
function onTranGridExpand(e) {
// save the Transaction ID value of the row that was just expanded in the browser session
// first get the data-uid of the row
var selectedRowID = e.masterRow.closest("tr.k-master-row").attr('data-uid');
// using the uid, retrieve the BatchID value and stor it in the session
$.post('@Url.Action("SetSessionVariable", "Home")',
{
key: 'lastSelectedTranID',
value: e.sender.dataSource.getByUid(selectedRowID).ID
});
}
function onTranGridDataBound(e) {
var lastSelectedTranID = '@Session["lastSelectedTranID"]';
var grid = e.sender;
var data = grid.dataSource.data();
var totalNumber = data.length;
for (var i = 0; i < totalNumber; i++) {
var currentDataItem = data[i];
if (currentDataItem.ID == lastSelectedTranID) {
var rowUID = currentDataItem.uid;
var row = grid.tbody.find("tr[data-uid='" + rowUID + "']");
grid.expandRow(row);
break;
}
}
}