2012-02-20 127 views
0

我正在使用Sigma網格,從PHP填充它。西格瑪應該有一個公式處理函數,但它似乎只適用於JS加載的數據集。所以我想知道是否可以在加載頁面後修改一些單元格,是否包含類似電子表格的公式?如何模擬電子表格

這是Sigma產品代碼(它的一個排): 19 2012-02-11 Bob LB 128 0 0 0


所以我想有效果是採用最後一個單元格,並添加前3倍單元格的值(內td和div)。

想法?

+0

好了,我沒有得到的代碼的竅門在這裏沒有格式化!以上每個項目都是< td >< div>項目< /div> – Onyx 2012-02-20 06:36:13

回答

0

添加以下到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(); 
    } 
    } 
+0

這個答案使用sigma grid的正確方法來處理更新記錄,以及在添加之前添加記錄並處理新值。 – Onyx 2012-03-05 02:36:19

0

已經知道了。此代碼只會大致適用於使用Sigma網格的其他人。

將其作爲單獨的JS文件加載到標題中。每次更改單元格時,它將啓動重新計算
,從而提供具有可編程公式的功能。

//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 
+0

實際上這對於sigma網格來說是錯誤的,因爲它將所有值存儲在內存中。 – Onyx 2012-03-05 01:34:50