Categories | Question details Back To List | ||
Reload tree has error I have a tree that refreshes when an item is dragged from a GRID to the tree. I have an item on the tree that serves as a recycle bin which when an item is dragged into it from the grid it deletes the item from the database then refreshes the tree - at this point i get the following error: Javascript ErrorThe next error ocured : 'parentObject' is null or not an object in http://dellbackup:200/directory.asp?tv=2 at line 25If you think that error can be caused by dhtmlxtree press the 'Generate report' button and send generated report to support@dhtmlx.com It wont show me a report to generate. My code is below: <script> //data var LANDING = 1 var XMLURL = "/inc_tree_functions_v2_data.asp?id=0"; //tree tree=new dhtmlXTreeObject("treeboxbox_tree","180px","100%",0); tree.setImagePath("/scripts/codebase/imgs/csh_bluefolders/"); tree.enableDragAndDrop(true); tree.setDragBehavior("complex"); tree.enableItemEditor(true); tree.setXMLAutoLoading(XMLURL); tree.enableKeySearch(true); tree.enableKeyboardNavigation(true); /**/ //on drag confirm you want to delete tree.setDragHandler(check_func); function check_func(id_drag, id_landing){ if (id_landing =="-1") { return confirm("Are you sure you want to delete this item?"); LANDING = "1" } else { LANDING = id_landing return true; } } //before edit check that its not recycle bin thats being edited. tree.attachEvent("onEdit",function(state,nodeId,tree,value){ if (nodeId != -1) { return true; } else { return false; } }) //Open the tree at the top (1) // BUG: when you press return when a node is selected tree.loadXML(XMLURL,function(){ tree.openItem('1'); }); //this function does the ONCLICK event stored in xml as a function tree.setOnClickHandler(doOnClick); function doOnClick(nodeId){ var myUrl = tree.getUserData(nodeId,"function"); eval(myUrl); } //back end processing myDataProcessor = new dataProcessor("inc_tree_functions_v2_processor.asp"); //myDataProcessor.enableDebug(true); myDataProcessor.init(tree); // Once processing is done then you can do some more work myDataProcessor.setOnAfterUpdate(function(nodeId,cType,newId){ tree.deleteChildItems(0); tree.loadXML(XMLURL,function(){ tree.openItem(LANDING); }); }); </script> Answer posted by Support on Jul 02, 2008 01:57 >>'parentObject' is null or not an object Such error can occur if you are executing command againg not existing item in tree. >>if (id_landing =="-1") { >>return confirm("Are you sure you want to delete this item?"); >>LANDING = "1" Is it correct, that operation executed after return ? Answer posted by John Watson on Jul 02, 2008 05:08 Basically the function below: //on drag confirm you want to delete This checks when the file is copied into the Recycle bin (ID = -1) so I keep a global var of the landing id so that if I need to refresh the tree once deleting something I refresh from the top (1) and not from the recycle bin (-1). Also, the error occurs after it successfully refreshes the tree. Thanks John Answer posted by Support on Jul 02, 2008 05:49 >>so I keep a global var of the landing id so that if I need to refresh the tree once deleting This is clear, but the line LANDING = "1" is never executed in above code, because it placed after return instruction. The code seems correct, the only possible place for error is tree.loadXML(XMLURL,function(){ tree.openItem(LANDING); // here , if LANDING has some incorrect value, error may occurs }); Answer posted by John Watson on Jul 02, 2008 13:20 Ahh that works a treat. Just one question.. How can i stop the grid from showing the item bold and struckthru when I have dragged it out onto the tree? Thanks John Answer posted by Support on Jul 08, 2008 02:35 >>How can i stop the grid from showing the item bold and struckthru when I have dragged it out onto the tree? This is caused by dataprocessor. Dataprocessor marks new row with bold text and deleted rows with strike-through. You can update dhtmlxdataprocessor.js line 163 this.obj.setRowTextBold(rowId); line 532 self.obj.setRowTextStyle(rowId,"text-decoration : line-through;"); You can change those line to some different visual styles, or just comment them ( it will not cause any side effects ) Answer posted by John Watson on Jul 08, 2008 02:53 I have done as you have said, but it also doesnt remove the item from the grid, how do I also remove the item from the grid? can i do that in the following: mygrid.gridToTreeElement = function(treeObj,treeNodeId,gridRowId){ ===function here to remove from grid=== Thanks John Answer posted by Support on Jul 08, 2008 03:18 If you are using dataprocessor in grid , then row will not be removed until confirmation from server received. You can achieve necessary visual behavior by changing self.obj.setRowTextStyle(rowId,"text-decoration : line-through;"); with self.obj.setRowHidden(rowId,true); Answer posted by John Watson on Jul 08, 2008 03:24 Thanks, that does work by adding the "hidden" code. However, the when I drag the item from the grid to the tree all server based work is done correctly, why do you think its not getting confirmation? GRID CODE (within an IFRAME): var mygrid; mygrid.enableMultiselect(true); //redefine grid-to-tree drop element } TREE CODE //data //on drag confirm you want to delete Answer posted by Support on Jul 08, 2008 08:38 It probably receives confirmation, but some time after d-n-d. You are using myDataProcessor.setUpdateMode("row"); which means , update in grid will start only after selection in grid was changed or Enter key pressed. In case of d-n-d from grid to tree, row in grid marked as deleted , but data sending to server not triggered. Row marked as deleted ( strike-through styling by default ) and awaits the sync. with server. After you trigger data sending, by selecting some row in grid - data will be sent to server , confirmation received and row fully removed from grid. If row not removed from grid, even after sync. with server done - it may be caused by incorrect server side response ( incorrect action or sid attribute value ) Answer posted by John Watson on Jul 08, 2008 09:19 Could it be that there is only server side action occuring within the tree? i.e. as the item is dropped on tree then the code in the dataprocessor (with tree) runs and removes the item from the database and therefore sends back confirmation to tree. Is there a way I can manually then send confirmation to grid? Answer posted by Support on Jul 08, 2008 09:56 The client side code of grid will be triggered in any case ( it react on deleteRow command ) , but the server side response is less predictable. You can try to add next code dataproc.afterUpdateCallback(id,id,"delete"); //id - id of row in question Reaction will be equal to server side response on delete action. |