Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Peter Ang on Jul 25, 2008 11:08
open dhtmlx forum
Custom Code:Adding new row then refreshing from server to get new ID is broken from upgrade 1.4 to 1.6

Hi. I am upgrading from 1.4 to 1.6. I have code to add a new row, send update to server to get a new id, change rowId of the new row from the update and do an updatefromxml to get data necessary for a new row. This is now broken.

CODE Below..

function addNewRow() {
    
    var newId = "New:" + Date.parse(new Date());
    mygrid.addRow(newId)    
    mygrid.setUserData(newId,"new","1");//mark row as NEW    
    mygrid.cells(newId,1).setValue( orderId);    
    sendServerCellUpdateRequest(newId);    
    lastrow = mygrid.rowsCol.length - 1;    
    mygrid.changePage(99);
    mygrid.selectRow(lastrow, false, false);
    
};

//send server request for upating/creating row
function sendServerUpdateRequest(rId){
    
    var rowValuesAr = getCellsArray(rId);    
    if(mygrid.getUserData(rId,"new")=="1"){
        var action = "add";
    }    
    var url = actionURL+"?do="+(!action?"update":action)+"&id="+rId+"&values="+rowValuesAr.join("|");
    rowUpdater.loadXML(url+"&un="+Date.parse(new Date()));    
};

cellUpdater = new dtmlXMLLoaderObject(doUpdateCell,window, false);

function doUpdateCell() {    
    var root = cellUpdater.getXMLTopNode("status");
    var oldId = root.getAttribute("oldid")
    var rowId = root.getAttribute("rowid")
    
    mygrid.setRowId(mygrid.getRowIndex(oldId), rowId)//set new row id (if it was chnaged for new row)
    mygrid.setRowTextNormal(rowId);
    
    mygrid.setUserData(rowId, "changed", "0")
    mygrid.setUserData(rowId, "new", "0")        
    mygrid.updateFromXMLSync(loadDataURL + "&rowId=" + rowId);        
    }
}


!!!!!!!!Below is broken, I am getting r has no properties...How can I get to the new row that was added.
mygrid.setRowId(mygrid.getRowIndex(oldId), rowId)//set new row id (if it was chnaged for new row)

Thanks
Peter Ang
    
Answer posted by Support on Jul 28, 2008 02:06
>>    lastrow = mygrid.rowsCol.length - 1;   
This code may return incorrect result, the grid has native method
    lastrow = mygrid.getRowsNum()-1;
it will return correct result in any mode ( including paging and SRND )

Please try to replace
    mygrid.setRowId(mygrid.getRowIndex(oldId), rowId)
with
    mygrid.changeRowId(oldId,rowId);

The setRowId may work incorrectly in case of SRND|paging mode - the issues already fixed in inner build, and will be released as part of oncoming update