Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Dennis on Oct 20, 2008 06:51
open dhtmlx forum
Error when deleting new row

Dear Sir/Madam,

I am using the TreeGrid and I am currently working on adding and deleting rows. Since the dataProcessor wasn't that useful for me I made my own .ASP page to update to the database. I call the pages using an Ajax Sack.

My problem comes in with adding rows. When I insert a row I immediately get the max id from my primairy key so that the rowid in the grid and the one in the database are identical; this works well. Also the grid adds a row with that rowid.

If i try to delete the row I get an error when using my ajax sack (_childIndexes is empty or not an object). Also when I try to edit the added row, afterwards it will auto-create a child row, which I don't want.

Please help me to solve my problem, I will send post my add and delete functions below.

======================CODE========================

function addRow()
{
var IDs = mygrid.getSelectedId();

ajax.requestFile = "updateDetailplanning.aspx?action=insert&parent="+IDs+"&ProjectNr="+Request("ProjectNr");
ajax.onCompletion = getMax;
ajax.method = "POST";
ajax.runAJAX();
}

function getMax()
{
var IDs = mygrid.getSelectedId();
var max = ajax.response;
mygrid.addRow(max,"./Images/Ico_ExclamationMark.GIF,,0","",IDs);
mygrid.cells(max,budgetIndex).setDisabled(false);
mygrid.setCellExcellType(max,budgetIndex,"ed");

mygrid.cells(IDs,budgetIndex).setDisabled(true);
mygrid.cells(IDs,budgetIndex).setValue(null);
mygrid.setRowColor(IDs,"#C6E2FF");
}

function deleteRow()
{
//alert("Are you sure you sure you want to delete the selected rows?"
var sID = mygrid.getSelectedId();//get id of selected row
var deleteFromDatabase = false;
var element = document.getElementById("test");
pID = mygrid.getParentId(sID);
element.innerHTML='ID: ' + sID + "PID: " + pID;
if(sID != null){

if(!mygrid.hasChildren(sID))
{
mygrid.deleteRow(sID);
alert(sID);
deleteFromDatabase = true;
}
else
{
alert("Can't delete rows that have children");
}
}

if(pID != null)
{
if(!mygrid.getAllSubItems(pID)){
mygrid.cells(pID,budgetIndex).setDisabled(false);
//mygrid.setCellExcellType(pID,budgetIndex,"ed");
mygrid.setRowColor(pID, "#FFFFFF");
}
}

if(deleteFromDatabase == true){
ajax.requestFile = "updateDetailplanning.aspx?action=delete&taakId="+sID;
ajax.method = "POST";
ajax.runAJAX();
}
}
Answer posted by Support on Oct 20, 2008 09:39
    Such an issue can take place if you advert to non-existent cell (row).

    Locally the issue can not be found. Try to debug you script and get the information about where exactly the issue appears.

   

Answer posted by Dennis on Oct 21, 2008 00:46
Sorry to bother you again, but I still can't find the problem.
There are all kind of strange problems going on. When I refresh the page most of it is normal again, although it loads from the database then.

But now an even stranger problem occurred; there is this method that checks if budget is 0 or above. And then changes the icon in an icon-column I made. All goes well if I check a boolean for false. But when I check it for true, it gives an error on the same code. (I get the; _childIndexes is empty or not an object - error).

Maybe this will make the problem more clear to you?

Thanks in advance.

===============CODE=====================
function checkBudgets(parentId)
            {
                var exclamationMark = false;
                var childs = mygrid.getAllSubItems(parentId).split(",");
                for (var i = 0; i < childs.length; i++)
                {
                    if(mygrid.cells(childs[i],budgetIndex).getValue()<1){
                        exclamationMark = true;
                    }
                }
               
                if(exclamationMark == false){
                    mygrid.cells(parentId,imageIndex).setValue("./Images/16x16_Background.GIF");
                }  
                if(exclamationMark == true){
                    //gives weird error
                    //mygrid.cells(parentId,imageIndex).setValue("./Images/Ico_Exclamation.GIF");
                    mygrid.cells(parentId,imageIndex).setValue("./Images/16x16_Background.GIF");
                }
               
                var parentIdParent = mygrid.getParentId(parentId);
                    if(parentIdParent != null){
                        checkBudgets(parentIdParent);
                }    
                  
            }
Answer posted on Oct 21, 2008 02:07
ah never mind, it was an Ajax method causing the problems when not having an onCompletion statement.

Thanks for you time and effort.