How to Set Active Row During Page Load in Master Detail
$dg->before_script_end
='setTimeout(function(){jQuery("#TABLE_NAME").jqGrid("setSelection", <ROW_ID>, true);}, 1000);';
Above should be inserted before calling display() method.
To always select the first row regardless row id, use
var ids = $("#TABLE_NAME").jqGrid('getDataIDs');
$dg->before_script_end ='setTimeout(function(){jQuery("#TABLE_NAME").jqGrid("setSelection", ids[0], true);}, 1000);';To expand subgrid during page load please see the following KB:
https://phpgrid.uservoice.com/knowledgebase/articles/319306-expand-all-subgrids-on-page-load