简体   繁体   中英

Calculate average of two sums from two column and show it in next column in JQGrid

I'm using Jqgrid with summery row at grouping level! Now I want to know one thing, that Is it possible to show average calculated from two summery of different column ? Because Sum is calculating by JQGrid functionality. That's why I'm not sure is it possible or not! Here I've attached my screen shot Please refer that. 在此处输入图片说明

In this the sum of forecast and revenue are is showing correctly. I Need to show the average of revenuesum/forecastsum*100 in the sum row place in Accuracy column. Is it possible to achieve it through any JavaScript coding or JQGrid functionality also?

Yes, it should be fairly straightforward to do this.

Start by adding in the name in the right location int he colModel, then in your jqGrid setup you can inject a blank column via:

        beforeProcessing: function (data, status, xhr) {
            //add a "blank" column that will be built
            for (var x = 0, length = data.rows.length; x < length; x++) {
                data.rows[x].cell.splice(ColumnIndexValueToAddBlank,0, "");
            }//for
        }, //beforeProcessing

then in that column setup in the jqGrid (in the right location in the colModel setup)

        { name: "CalculatedColumn", .... , formatter: CalculatedFormatFunction

The custom formatter function:

  function CalculatedFormatFunction(cellval, opts, rowObject, action) {

   return rowObject[ColumnOneIndex] * rowObject[ColumnTwoIndex]; 
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM