1

I am developing a Grid using JQgrid. I've used GroupView and each group has 2 values. I want to subtract both values and give result in the next row.

JQgrid by default provides sum function. It doesn't have anything for subtraction.

I've written below code in cellAttr property and I am able to get the subtraction value. but with cellAttr I am not able to put the result value in particular cell.

cellattr: function(rowId, tv, rawObject, cm, rdata) {
  arr[i] = parseInt(tv, 10);
  if ((rowId % 3) == 0) {
    var value = arr[i - 2] - arr[i - 1];
    console.log(" Value : " + value);
  }
  i++;
}

I've tried writing the custom function in Summarytype property. But I can not access the value of each row in it. (Like I can have cell value in 'tv' argument of cellAttr) Is there any way I could write this logic in summaryType property or any other way I could subtract the values of group?

Pete
  • 57,112
  • 28
  • 117
  • 166
Parth
  • 11
  • 2

1 Answers1

1

The usage of cellattr seems me not what you need. I think that you should define summaryType in colModel as function. The function will be called for every row of the group and you can make all required custom calculations. I would recommend you to read the answer which provides JSFiddle demos which demonstrates the usage of summaryType as function. Other answers (this one and this one) are more complex and there shows how to implement more complex scenarios.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798