Delete a row in a grid

Hi,

I use the deleteSelectedRows function and it works fine, but in a case i want that the server sends an error for example (<?xml version="1.0" encoding="ISO-8859-1" ?>1).

The problem is on next event the request is resend to the server, so it loops.

How the selected rows added to deleted rows array could be unselected so that the request is not send another time.



Thanks

In your code, which process error response you need to add next line

    dataprocessor.setUpdated(row_id,false);

It will remove row from collection of updated rows.

this the code of my handler

myDataProcessor.defineAction(“error_undeletable”, undeletableHandler);

    function undeletableHandler(obj){
        var rowId = obj.firstChild.nodeValue - 1;
        alert(“row id” + rowId);
        mygrid.selectRow(rowId, false, false, true);
        alert(“Error occured.\nThis record cannot be deleted.”);
        myDataProcessor.stopOnError = true;
        myDataProcessor.setUpdated(rowId,false);
        return false;
    }

and i got an error on line 1996 in dhtmlxgrid_debug.js
this.getRowById(row_id) -> null

so, where is my error ?

Are you using native grid behavior, when deleted row just marked , or has modified code, so record deleted for sure ?
The mentioned error may occur only if row with specified ID not found in grid ( which must not occur in case of native behavior )

In any way, please try to replace problematic line with
    myDataProcessor.updatedRows[myDataProcessor.findRow(rowId)]=null;
It will work correctly even if row was deleted for sure.

the error in dhtmlxgrid_debug.js doesn’t occur now.
But the request for deleting the row still be send to the server !!
the state of the row isn’t delete.

Any solution ?
thanks

If you deleting row from updatedRows array - it must not generate any calls to server.
You can try to add one more command to clear “delete” status of row

    function undeletableHandler(obj){
        var rowId = obj.firstChild.nodeValue - 1;
        alert(“row id” + rowId);
        mygrid.selectRow(rowId, false, false, true);
        alert(“Error occured.\nThis record cannot be deleted.”);
        myDataProcessor.stopOnError = true;
        myDataProcessor.updatedRows[myDataProcessor.findRow(rowId)]=null;
        mygrid.setUserData(rowId,"!nativeeditor_status","")
        return false;
    }

Please be sure that rowID value returned from server is exactly the same as ID of row in grid.

There’s no change. :frowning:
I think my valueof rowid is correct, because the mygrid.selectRow(rowId, false, false, true); method select the right row in my grid.
but the myDataProcessor.findRow(rowId) method return -1.

If myDataProcessor.findRow(rowId) returns -1 that means that row not marked as updated and its data must not be send to the server again.
You can check the content of
       myDataProcessor.updatedRows
this array, contains IDs of updated rows

If you have any kind of online sample where issue can be reconstructed please contact us directly at support@dhtmlx.com

myDataProcessor.updatedRows contains one id which is the id of the row selected for deleting
why myDataProcessor.findRow(rowId) return -1 ?

if i put myDataProcessor.updatedRows[0]=null; the request is not send again.
but i mus’nt have multi-selction in my grid.

in this case (not sending the request again), how can i put the row to the original style ?

i’ve got no sample online.

instead of using myDataProcessor.updatedRows[0]=null; i use myDataProcessor.updatedRows=new Array(0);
i’ve got not request send.
But there’s another problem
i can’t try to delete the row after, and more serious, if i change data in my row that the conditions of deletion is ok, the row is deleted.
So i understand nothing.

How i can put my grid in a standard state after an event (update/delete), so that there’s no interaction like the last one ?
I wan’t something like myDataprocessor.deleteAllDataToUpdateOrDelete

Thanks


dataProcessor.prototype.deleteAllDataToUpdateOrDelete(){
    for (var i=0; i<this.updatedRows.length; i++)
       if (this.updatedRows[i])
          this.obj.setUserData(this.updatedRows[i],"!nativeeditor_status","");
    this.updatedRows[i] = new Array(0);
}

It was a sample for the method !!
there’s no mecanism in dhtmlxgrid that can remove all events and data state. The goal is that my grid goes to a stable state like after a load.

Maybe what i made is not the right solution to achieve what i want ?

there’s no mecanism in dhtmlxgrid that can remove all events and data state.
There is no API command to such operation, but you can reinit grid if necessary, something similar to next

grid.setSerializationLevel(true,true,true);
var state = grid.serialize();   //get current state
grid.destructor();
grid = new dhtmlXGridObject(‘some’)
grid.loadXMLString(state);

basically it destroys old grid and create new one with same data

i’ve already think of this solution but i loose pagination, filters and sorts, and i want to keep them.
is it possible to implement such a command in API ?

There are a lot of possible options|modes so it pretty complex to fully restore grid’s state to initial one.
If limit the set of properties which need to be restored - it can be done with some custom code, but restore ALL setting to initial ones is pretty complex task.

So ok, i’ll put my control before the call of the deleteSelectedRows.
But i think you should have a mecanism which will restore the grid in a state identical of the state before an event is launched like a rollback in a database.