davidguttman / react-pivot

React-Pivot is a data-grid component with pivot-table-like functionality for data display, filtering, and exploration.
http://davidguttman.github.io/react-pivot/
1.05k stars 147 forks source link

Is there a way to calculate percentages for each row corresponding to group total #72

Open rrameshkumar76 opened 5 years ago

rrameshkumar76 commented 5 years ago

Is there a way to calculate percentages for totals columns for each row corresponding to group total

Basically if there is a way to to get the group total or the row in calculations for the level above.

If not I guess we need to pass back the parent record to the template

rrameshkumar76 commented 5 years ago

May could do something like

renderTableBody: function (columns, rows) {
    var self = this
    var parents = new Map()
    return (
      <tbody>
      {rows.map(function (row) {
        parents.set(row._level, row)
        return (
          <tr key={row._key} className={"reactPivot-level-" + row._level}>
            {columns.map(function (col, i) {
              if (i < row._level) return <td key={i} className='reactPivot-indent' />
              var topLevelParent = parents.get(0)
              var previousLevelParent = row._level > 0 ? parents.get(row._level - 1) : topLevelParent
              return self.renderCell(col, row, topLevelParent, previousLevelParent)
            })}
          </tr>
        )

      })}
      </tbody>
    )
  },

to calculate all the parents and pass to the renderCell and from there to template methods