DHTMLX Docs & Samples Explorer

Common Tasks

a) Waiting for finishing update. There are two events which can be used to catch finish of data sync operation:

  dp.attachEvent("onAfterUpdateFinish",function(){
      alert("single row updated")
  });
  dp.attachEvent("onFullSync",function(){
      alert("all rows updated")
  });

In any moment of time update state can be checked as follows:

  dp.getSyncState()

which will return true if all data synced with server and false otherwise

b) Manual row updating. The dataprocessor detects the row changed only by edit operations. If a row was changed by a direct API calling it will not be updated. You can manually call the dataprocessor to inform about the update operation:

      grid.cells(id,ind).setValue(new_one)
      dp.setUpdated(id,true);

The row can be marked as “not updated” in the same manner (may be useful in some scenarios):

      dp.setUpdated(id,false);

If you want to mark row with status different from “updated” (not sure how it can be useful, but still ) it can be done as below:

       dp.setUpdated(id,true,"status name");

c) Error catching.

Starting version 2.1, dataprocessor has default reaction on “error” response type, which can be used to report about server side errors. Row marked as error will be highlighted in grid. And it will not be sent back to server until one of the next events occurs:

  • user edit data in row;
  • rows set back to updated status through setUpdated command.

d) Sever side validation.

There is a built in support for “invalid” status in server side response. It's similar to “error”, but has different visual marking.

If you want to extend it, you should do the following:

  dp.defineAction("invalid",function(sid,response){
            var message = response.getAttribute("message");
            alert(message);
 
 
 
            return true;
  })

now you can do the next on server side, if data is not valid you can just output the next instead of valid response:

<data>
 <action sid="{gr_id}" type="invalid" message="Data in first column is not valid" />
 </data>

e) Loading extra data during update.

It's possible to extend default after-update reaction as:

  dp.defineAction("updated",function(sid,response){
            var sid = response.getAttribute("sid");
            var extra = response.getAttribute("extra");
            this.obj.cells(id,0).setValue(extra);
            return true;
  })

with such code you will be able to specify any additional data which needs to be updated in grid after receiving xml response from the server:

<data>
 <action sid="{gr_id}" type="updated" tid="{gr_id}" extra="new value for first column" />
 </data>