Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Jul 01, 2008 13:01
open dhtmlx forum
grid v1.5

I am trying to implement a cancel edit functionality on my grid which means i can roll back my changes made to a row by clicking cancel button on the page. Inorder to achieve this iam trying to put all the column values of the selected row inside an array so that i can place them back if the user clicks cancel.

mygrid.attachEvent("onRowSelect",function()
{
var id = mygrid.getSelectedId();
var z=myDataProcessor.obj.getUserData(id,"!nativeeditor_status");
var colCount =mygrid.getColumnCount();
if(z !="inserted" || z !="deleted")
{
for(var i=0;i<colCount ;i++)
{
rowData[i] = mygrid.cells(id,i).getValue();}}});


But the problem is that the rowData array has the modified values instead of the old values. Why is this happening?
Answer posted by Support on Jul 02, 2008 01:50
The onRowSelect event generated for each click inside selected row, so if you have selected row, changed value in cell and clicked again to edit another cell in same row - attached code will be called again, and store updated values instead of original one - basically , you need to add one more check.

mygrid.attachEvent("onRowSelect",function(id){
    var z=this.getUserData(id,"!nativeeditor_status");
    if(z !="inserted" || z !="deleted") return;
    if (rowData && rowData._id==id) return;// prevent second call against the same row

    rowData=[];
    mygrid.forEachCell(id,function(cell){
        rowData.push(cell.getValue());
     });
     rowData._id=id;//store id of related row
});