Accessing a SubGrid

I am going thru the rows of a grid and when I come to a subgrid - I want to access it and go thru its rows - here is some code I am trying:

var rowids = (grid.getAllRowIds()).split(’,’);

for (var inx = 0; inx < rowids.length; inx++) {

if(/^Changes:(\d+)$/.test(rowids[inx])) {

var cell = grid.cellById(rowids[inx], 0);
alert("CELL = " + cell);

var sg;
 if(cell) sg = cell.getSubGrid()
 alert("SUBGRID = " + sg);         


I got getSubGrid() from: … me_excells

This code comes back with a valid cell object - and the call expands the subgrid - BUT the sub grid is undefined.

Any ideas?

Thanks in advance…

Sub grid object is defined only after you opened sub grid row at list once.