0

I am working with Sigma grid, populating it from PHP. Sigma is supposed to have a formula handling function, but it only seems to work with JS loaded datasets. So I was wondering if it was possible to modify some of the cells after load of page, do include spreadsheet-like formulae?

This is the code produced by Sigma (one row of it): 19 2012-02-11 Bob LB 128 0 0 0


So the effect I want to have is to take the last cell, and add the previous 3 cell values (inside td and div each).

Ideas?

Onyx
  • 876
  • 1
  • 10
  • 18
  • ok, so I haven't got the hang of code formatting here yet! each of those items above is a < td > < div> item < /div> < / td> – Onyx Feb 20 '12 at 06:36

2 Answers2

0

Have figured it out. This code will only roughly apply to someone else using Sigma grid.

Load this as a separate JS file in the header. It will initiate a recalculation
every time a cell is changed, thereby offering the ability to have programmable formulae.

//now load the values from the retrieved table, after a change initiated by user
$(window).change(function() {

    //all formulae go below here:
// Ordered trays formula
$('table.gt-table tbody tr').each(function() {
    var tray = 0;
    var ordcell = 0;

var traycode= $(this).find("td.gt-col-mygrid1-trays_code div").html();  
 var ordcells= $(this).find("td.gt-col-mygrid1-ordered_cells div").html();  
 if (parseInt(traycode) >0) { 
     tray = parseInt(traycode); 
     } else { 
     tray = 0;
 }
   if (parseInt(ordcells) >0) { 
     ordcell = parseInt(ordcells); 
     } else { 
     ordcell = 0;
 }
 if (tray > 0 && ordcell > 0)  var ordtrays = ordcell/tray;
if (ordtrays > 0){
    $(this).find("td.gt-col-mygrid1-ordered_trays div").html(ordtrays);
}
});
// end Ordered trays formula


}); // end the window change function
Onyx
  • 876
  • 1
  • 10
  • 18
  • Actually this is wrong for sigma grid, because it stores all of it's values in memory. – Onyx Mar 05 '12 at 01:34
0

Add the following to the gridoption

onCellClick: function(value, record , cell, row,  colNo, rowNo,columnObj,grid){

overRowNo=rowNo;
overColNo=colNo;
cellValue=value;

},
afterEdit: function(  value,  oldValue,  record,  col,  grid){
// ordered trays calculation
    if(overColNo == 5 || overColNo == 6){       
    var text = $(this.activeCell).find('div.gt-inner').text();console.log(text);
    if (!$.isNumeric(text)){ //jquery's isnumeric function
         alert ('Please enter a valid number.');
         // because cell 5 is a drop down select we don't need to scan for bad input; this is only for cell 6 - ordered cells
         text = 0;
     }
            var traycode = mygrid.getColumnValue(5,overRowNo);
            var ordcells = mygrid.getColumnValue(6,overRowNo);
             if (parseInt(traycode) >0) { 
             tray = parseInt(traycode); 
             } else { 
                tray=text;


         }
           if (parseInt(ordcells) >0) { 
             ordcell = parseInt(ordcells); 
             } else {               
                 ordcell= $('input.gt-editor-text').first().val();  
         }
         //alert(tray+' '+ordcell);
         if (tray > 0 && ordcell > 0)  var ordtrays = Math.ceil(ordcell/tray);
        if (ordtrays > 0){
        mygrid.setColumnValue('ordered_trays',overRowNo,ordtrays);
         mygrid.updateEditState();
           mygrid.activeRecord.ordered_trays = ordtrays;

    mygrid.refresh();
    }
    }
Onyx
  • 876
  • 1
  • 10
  • 18
  • this answer use the correct methods of sigma grid, to handle updating records, as well as adding records and dealing witht he new values before addition. – Onyx Mar 05 '12 at 02:36