Grid 3.5 Pro Adding subgrid to grid after grid is created

I am trying to add a subgrid after a user enters data in a row for the primary grid. Looking in the forum, it said to use setCellExcellType and then setValue(). The event onSubGridCreated fires after setValue() is called, creates the subgrid, with headers / titles but no data. I’ve modified the boths grids to use .csv and different delimiters. I tried getSubGrid() but it came back as undefined. Any help would be great, as my javascript is limited.

Below is the code:
function doInitDRGrid(){
bbyDRgrid = new dhtmlXGridObject(‘bbygrid_daily_receipts_container’);
bbyDRgrid.setImagePath(“/eb2b-jscripts/dhtmlxGrid/imgs/”);

bbyDRgrid.setHeader(“v1st-DR-hdr”,null,[v1st-DR-hdr-style]);
bbyDRgrid.attachHeader(“v2nd-DR-hdr”,[v2nd-DR-hdr-style]);
bbyDRgrid.attachHeader(“v3rd-DR-hdr”,[v2nd-DR-hdr-style]);
bbyDRgrid.setColTypes(“ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ed,ro,ro,ro,ro”);
bbyDRgrid.setInitWidths(“100,100,100,100,100,100,100,75,75,75,75,75,75,60,0”);
bbyDRgrid.setColAlign(“right,right,right,right,right,right,right,right,right,right,right,right,right,center,right”);
bbyDRgrid.setColSorting(“str,str,str,str,str,str,str,ron,ron,str,int,int,int,str,str”);
bbyDRgrid.setColTypes(“ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ed,ro,ro,ro,ro”);
bbyDRgrid.setInitWidths(“25,100,100,100,100,100,100,100,75,75,75,75,75,75,60,0”);
bbyDRgrid.setColAlign(“center,right,right,right,right,right,right,right,right,right,right,right,right,right,center,right”);
bbyDRgrid.setColSorting(“str,str,str,str,str,str,str,str,ron,ron,str,int,int,int,str,str”);
bbyDRgrid.setColumnColor(“vcol-shades”);
bbyDRgrid.attachEvent(“onEditCell”, doOnDRCellEdit);
bbyDRgrid.setSkin(“grey”);
bbyDRgrid.setDateFormat(“%m/%d/%Y”);
bbyDRgrid.setMathRound(2);
bbyDRgrid.setEditable(false);
bbyDRgrid.setNumberFormat(“0,000.00”,DR_ReceiptCost);
bbyDRgrid.enableRowsHover(true,‘grid_hover’)
bbyDRgrid.enableEditEvents(true, false, false);
bbyDRgrid.enableEditTabOnly(true);
bbyDRgrid.setStyle(“”,“”,“”,“background-color:#686868;color:white; font-weight:bold;”);
bbyDRgrid.csv.row = “^”;
bbyDRgrid.csv.cell = “|”;
bbyDRgrid.attachEvent(“onSubGridCreated”,function(subgrid){

   subgrid.setHeader("A,B,C");
   subgrid.setColTypes("ro,ro,ro");
   subgrid.setInitWidths("100,100,100");
   subgrid.csv.row = "^";
   subgrid.csv.cell = "|";
   subgrid.init();

   alert("sub grid event fired");
   return false;  // block default behavior
});

bbyDRgrid.init();
bbyDRgrid.setColumnHidden(DR_Receipt_Rowid,true);

loadDailyReceiptsGrid(); // load data in to DR Grid

} // doInitDRGrid

function doOnDRCellEdit(stage, rowId, colInd, newValue, oldValue) {
var selectedDRDisputeRow = null;

selectedDRDisputeRow        = bbyDRgrid.getSelectedRowId();


if (stage == 0) 
{
} 
else if (stage == 1) 
{
} // stage 1 
else if (stage == 2) 
{
    if (colInd == DR_ReceiptUnits) 
    {

      bbyDRgrid.setCellExcellType(selectedDRDisputeRow,0,"sub_row_grid");
      bbyDRgrid.cellById(selectedDRDisputeRow,0).setValue('hi|there|Rich^test|sub|grid^');
      // grid.cells(i,j).getSubGrid();
      // bbyDRgrid.cells(selectedDRDisputeRow,0).getSubGrid().loadCSVString('hi|there|Rich^');
      

   } // colInd == DR_ReceiptUnits           

} // stage 2

return true;

} //function doOnDRCellEdit

Hello.

You should populate your data to the subgrid from the onSubgridCreated event. Otherwise you will populate it before the actual subgrid was created:

                bbyDRgrid.attachEvent("onSubGridCreated", function (subgrid) {
                    subgrid.setHeader("A,B,C");
                    subgrid.setColTypes("ro,ro,ro");
                    subgrid.setInitWidths("100,100,100");
                    subgrid.csv.row = "^";
                    subgrid.csv.cell = "|";
                    subgrid.init();

                    subgrid.loadCSVString('hi|there|Rich^') // load the data here

                    subgrid.callEvent("onGridReconstructed",[])
                    subgrid.setSizes();
                    bbyDRgrid.setSizes();
                    alert("sub grid event fired");
                    return false; // block default behavior
                });

Sematik,

Thank you, that did the trick.

Regards,

Rich