Calculating total in footer with Mysql dataprocessor

I’m trying to show a total value in the footer of a grid. Somehow this total value is always one edit behind on the edit.
Seems like the event ‘onFullSync’ is called before the (read-only) grid values are updated. Somebody have an advice how to solve this?

Workflow:

  • user enters columns Qty and PartNr
  • dataprocessor is linked to Mysql database with functionality that returns a.o. fields Qty,PartNr,TotalValue (this is working great, TotalValue is shown in a ‘ron’ column)
  • in footer should appear the total of these ‘TotalValue’ values.

Essentials of my script:

var mygrid; 
function doInitGrid(){
	mygrid = new dhtmlXGridObject('mygrid_container');
	mygrid.attachFooter(",,Totaal,,,,,,<div id='nrT'>0</div>");
	mygrid.init();
	mygrid.load("gridserver.php");

	var myDP = new dataProcessor("gridserver.php");
	myDP.init(mygrid);
	myDP.defineAction('updated',function(sid,response){
		mygrid.updateFromXML("gridserver.php");
		return true;
	})
	myDP.attachEvent('onFullSync', function() {
		calculateFooterValues();
	});
}

function calculateFooterValues(stage) {
	var nrT = document.getElementById('nrT');
	nrT.innerHTML=sumColumn(9);
	return true;
}
function sumColumn(ind) {
	var out = 0;
	for (var i = 0; i < mygrid.getRowsNum(); i++) {
		out += parseFloat(mygrid.cells2(i, ind).getValue());
	}
	return out;
}

Try the next code

   myDP.defineAction('updated',function(sid,response){
      mygrid.updateFromXML("gridserver.php",true, false, function() {
           calculateFooterValues();
      });
   });

Stanislav, Thanks a lot! With your code the total is now updated correct after editing a cell.

Only thing left is the initial calculation on load. This is still 0 until a first cell edit.

You can use a callback of the load method

grid.load(url, function(){
   ... call total calculation here ...
})

Great! It’s working now.

Today I realized a grid interface to our database in a couple of hours with the dhtmlxGrid and the helpful comments of Stanislav. A functionality we have been dreaming of for several years. :slight_smile: