I solved the problem by collapsing the previously expanded row in the main datagrid.
I hold the index of the previously selected row. Then in each expansion of a row, I collapse the previously expanded row.
In this way, only one row is expanded in the master datagrid and this prevents confusion.
This is my code
var selectedIndex=-1;
.....................................
onExpandRow: function (index, row) {
//collapse previously expanded parent row.
if (selectedIndex>-1 && selectedIndex!=index)
$(this).datagrid('collapseRow',selectedIndex);
selectedIndex=index;
..................
}
I am also open to other solutions.