mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

to get the totals in a separate column #1028

Closed greeniee closed 9 years ago

greeniee commented 9 years ago

i want to get both row totals as well the COLUMNS TOTAL in the slickgrid... the rows total is possible from the available example... i am not able to figure out what must be changed in the existing code(of the example provided by slickgrid: example-totals-via-data-provider.html) so that i can get totals column in the grid..

jeddi commented 9 years ago

try this:

Step 1: add column "Total"

columns.push({
  id: "rowTotal",
  name: "Total",
  field: "rowTotal"
  cssClass:"totals"
});

Step 2 add method setRowTotal to provider (in TotalsDataProvider)

this.setRowTotal = function(item){
  var rowTotal = 0;
   for (var i = 0; i < 10; i++) {
     rowTotal += item[i]; 
   }
   item.rowTotal = rowTotal;
}

Step 3 replace getItem method

this.getItem = function(index) {
  item =  (index < data.length) ? data[index] : totals;
  this.setRowTotal(item);
  return item;
};
greeniee commented 9 years ago

thanks a lot !!... works fine ...