Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Mate Ordody on Oct 15, 2007 08:37
open dhtmlx forum
Getting database id of a newly added row

I have a table with auto-increment id. When I insert a new row, I use 0 for the id, to get the next available. Then I need the actual id for my later scripts.

I have:

lastid=0
kgrid.addRow((new Date()).valueOf(),[lastid,'','','','','','','','','','',''],0)

After a successful addRow() I get:

<?xml version="1.0" encoding="UTF-8"?><data ><action type='insert' sid='1192461668687' tid='36'/></data>

where tid is the id of my row in the database.
How can I get it?

This one says the sid only:

kgrid.setOnRowCreated(Func);
function Func(a,b,c)    {
    alert(a)
}

Thank you
Mate
Answer posted on Oct 15, 2007 09:15
You need to catch dataProcessor callback, it can be done in next way

dp - dataprocessor object

    dp.defineAction("update",my_handler);
    function my_handler(xml_node){
        alert(xml_node.getAttribute("tid"));
        return true;
    }