Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Chris on Jan 04, 2010 04:44
open dhtmlx forum
error adding row in subgrid by contect menu in maingrid

hi
the function "addRow" the following code throws the error "Error: this.obj.firstChild is null'

code snippet:

switch (menuitemId) {
        case "newContactAddress":
            var data=memberGrid.contextID.split("_");
            memberGrid.cellById(data[0],0).open();
            var mysubgrid = memberGrid.cellById(data[0],0).getSubGrid();
                subGridDp.setUpdateMode("off");
                mysubgrid.addRow("newAddressRow",[1,null,null,null,null,null,150,null,null,null,null,null]);
                mysubgrid.setUserData("newAddressRow","stamm_ID",memberGrid.getUserData(data[0],"stamm_ID"));
                subGridDp.sendData();
                subGridDp.setUpdateMode("cell");
            return true;
        break;

this happens only when i add a new row to the subgrid by clicking a topic from contextual menu from the _first_ row in maingrid (memberGrid). else it works like a charm (e.g. clicking contextual menu in second row in maingrid).

the error is made in dhtmlxGrid/codebase/dhtmlxgrid.js, line 853
any suggestions? thx
Answer posted by dhxSupport on Jan 05, 2010 03:03
Unfortunately we cannot reproduce this issue locally. Please provide us complete example where we can reproduce it. Content of complete example you can find here http://www.dhtmlx.com/docs/support/what_is_a_completed_demo.htm
Answer posted by Chris on Jan 05, 2010 03:46
I found out why this happend:
mysubgrid.addRow("newAddressRow",[1,null,null,null,null,null,150,null,null,null,null,null]);
only works, if
memberGrid.cellById(data[0],0).open();
has finished!

Since the subgrid is loaded by dynamic xml it takes too long to open the subgrid and the addRow()-functon is called before the subgrid has built the firstChild-Object.
I solved it with adding a little alert-statement which enables the grid's open()-process to finish BEFORE the subgrid's addRow()-function is called.
It's a nasty work around. Would be cool to have some listener on the grid's open()-function which runs code only, if subgrid-cell is fully opened.
Answer posted by dhxSupport on Jan 05, 2010 03:52
>>Would be cool to have some listener on the grid's open()-function which runs code only, if subgrid-cell is fully opened.
To handler if sub grid was loaded you can use onSubGridLoaded event http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxgrid:event_onsubgridcreated_onsubgridloaded
Events could be attached\detached as well. http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxgrid:attaching_custom_code_to_events