Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Mikkel on Sep 23, 2008 23:31
open dhtmlx forum
User data in dataprocessor

I am using the dataprocessor to edit a grid with data from a database table where some of the columns are populated by triggers after insert. Some of these columns are shown in the grid and some are added as user data. Is there any way such column values can be returned to the grid by the serverProcessor after an insert operation? The problem is that existing rows have userdata needed by scripts that the new rows are missing.

/Mikkel
Answer posted by dhtmlx support on Sep 24, 2008 06:24
You can set custom server side response. Please, see article in the documentation:

http://www.dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Dataprocesor_usage.html

Answer posted by Mikkel on Sep 24, 2008 08:33
OK. I had hoped there was some build in feature. I managed to implement it as custom insert handler that accepts server responses like this:
<data>
 <action type="insert" sid="1222270111876" tid="222">
  <userdata name="UNIT_KEY" value="222"/>
<column name="AVAILABLE" value="1"/>
</action>
</data>
It would be nice to have something like this as a build in feature in a future release.

this.dataProcessor.defineAction("insert", this.associateObjWithEvent(this, "afterInsert"));


GridObject.prototype.afterInsert = function(btag) {
    var grid = this.grid;
    var action = btag.getAttribute("type");
    var sid = btag.getAttribute("sid");
    var tid = btag.getAttribute("tid");

    for (var j = 0; j < btag.childNodes.length; j++) {
        var ctag = btag.childNodes[j];
        if (ctag.tagName == "userdata") {
            grid.setUserData(sid, ctag.getAttribute("name"), ctag.getAttribute("value"));
        } else if (ctag.tagName == "column") {
            var idx = grid.getColIndexById(ctag.getAttribute("name"));
            if (idx!=undefined) {
                grid.cells(sid, idx).setValue(ctag.getAttribute("value"));
            }
        } else {
            continue;
        }
    }
    return true;
};