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;
}