Search code examples
jquerysigma-grid-control

How to simulate a spreadsheet


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?


Solution

  • 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();
        }
        }