@@ -61,21 +61,27 @@ function makeRenderer(opts = {}) {
6161 const rowKeys = pivotData . getRowKeys ( ) ;
6262 const colKeys = pivotData . getColKeys ( ) ;
6363 const grandTotalAggregator = pivotData . getAggregator ( [ ] , [ ] ) ;
64+ const tableOptions = this . props . tableOptions ;
65+ const rowTotals = ( 'rowTotals' in tableOptions ? tableOptions . rowTotals : true ) || colAttrs . length === 0 ;
66+ const colTotals = ( 'colTotals' in tableOptions ? tableOptions . colTotals : true ) || rowAttrs . length === 0 ;
6467
6568 let valueCellColors = ( ) => { } ;
6669 let rowTotalColors = ( ) => { } ;
6770 let colTotalColors = ( ) => { } ;
6871 if ( opts . heatmapMode ) {
6972 const colorScaleGenerator = this . props . tableColorScaleGenerator ;
70- const rowTotalValues = colKeys . map ( x =>
71- pivotData . getAggregator ( [ ] , x ) . value ( )
72- ) ;
73- rowTotalColors = colorScaleGenerator ( rowTotalValues ) ;
74- const colTotalValues = rowKeys . map ( x =>
75- pivotData . getAggregator ( x , [ ] ) . value ( )
76- ) ;
77- colTotalColors = colorScaleGenerator ( colTotalValues ) ;
78-
73+ if ( colTotals ) {
74+ const rowTotalValues = colKeys . map ( x =>
75+ pivotData . getAggregator ( [ ] , x ) . value ( )
76+ ) ;
77+ rowTotalColors = colorScaleGenerator ( rowTotalValues ) ;
78+ }
79+ if ( rowTotals ) {
80+ const colTotalValues = rowKeys . map ( x =>
81+ pivotData . getAggregator ( x , [ ] ) . value ( )
82+ ) ;
83+ colTotalColors = colorScaleGenerator ( colTotalValues ) ;
84+ }
7985 if ( opts . heatmapMode === 'full' ) {
8086 const allValues = [ ] ;
8187 rowKeys . map ( r =>
@@ -164,7 +170,7 @@ function makeRenderer(opts = {}) {
164170 ) ;
165171 } ) }
166172
167- { j === 0 && (
173+ { j === 0 && rowTotals && (
168174 < th
169175 className = "pvtTotalLabel"
170176 rowSpan = {
@@ -239,55 +245,61 @@ function makeRenderer(opts = {}) {
239245 </ td >
240246 ) ;
241247 } ) }
242- < td
243- className = "pvtTotal"
244- onClick = {
245- getClickHandler &&
246- getClickHandler ( totalAggregator . value ( ) , rowKey , [ null ] )
247- }
248- style = { colTotalColors ( totalAggregator . value ( ) ) }
249- >
250- { totalAggregator . format ( totalAggregator . value ( ) ) }
251- </ td >
248+ { rowTotals && (
249+ < td
250+ className = "pvtTotal"
251+ onClick = {
252+ getClickHandler &&
253+ getClickHandler ( totalAggregator . value ( ) , rowKey , [ null ] )
254+ }
255+ style = { colTotalColors ( totalAggregator . value ( ) ) }
256+ >
257+ { totalAggregator . format ( totalAggregator . value ( ) ) }
258+ </ td >
259+ ) }
252260 </ tr >
253261 ) ;
254262 } ) }
255263
256- < tr >
257- < th
258- className = "pvtTotalLabel"
259- colSpan = { rowAttrs . length + ( colAttrs . length === 0 ? 0 : 1 ) }
260- >
261- Totals
262- </ th >
263-
264- { colKeys . map ( function ( colKey , i ) {
265- const totalAggregator = pivotData . getAggregator ( [ ] , colKey ) ;
266- return (
264+ { colTotals && (
265+ < tr >
266+ < th
267+ className = "pvtTotalLabel"
268+ colSpan = { rowAttrs . length + ( colAttrs . length === 0 ? 0 : 1 ) }
269+ >
270+ Totals
271+ </ th >
272+
273+ { colKeys . map ( function ( colKey , i ) {
274+ const totalAggregator = pivotData . getAggregator ( [ ] , colKey ) ;
275+ return (
276+ < td
277+ className = "pvtTotal"
278+ key = { `total${ i } ` }
279+ onClick = {
280+ getClickHandler &&
281+ getClickHandler ( totalAggregator . value ( ) , [ null ] , colKey )
282+ }
283+ style = { rowTotalColors ( totalAggregator . value ( ) ) }
284+ >
285+ { totalAggregator . format ( totalAggregator . value ( ) ) }
286+ </ td >
287+ ) ;
288+ } ) }
289+
290+ { rowTotals && (
267291 < td
268- className = "pvtTotal"
269- key = { `total${ i } ` }
270292 onClick = {
271293 getClickHandler &&
272- getClickHandler ( totalAggregator . value ( ) , [ null ] , colKey )
294+ getClickHandler ( grandTotalAggregator . value ( ) , [ null ] , [ null ] )
273295 }
274- style = { rowTotalColors ( totalAggregator . value ( ) ) }
296+ className = "pvtGrandTotal"
275297 >
276- { totalAggregator . format ( totalAggregator . value ( ) ) }
298+ { grandTotalAggregator . format ( grandTotalAggregator . value ( ) ) }
277299 </ td >
278- ) ;
279- } ) }
280-
281- < td
282- onClick = {
283- getClickHandler &&
284- getClickHandler ( grandTotalAggregator . value ( ) , [ null ] , [ null ] )
285- }
286- className = "pvtGrandTotal"
287- >
288- { grandTotalAggregator . format ( grandTotalAggregator . value ( ) ) }
289- </ td >
290- </ tr >
300+ ) }
301+ </ tr >
302+ ) }
291303 </ tbody >
292304 </ table >
293305 ) ;
@@ -297,7 +309,7 @@ function makeRenderer(opts = {}) {
297309 TableRenderer . defaultProps = PivotData . defaultProps ;
298310 TableRenderer . propTypes = PivotData . propTypes ;
299311 TableRenderer . defaultProps . tableColorScaleGenerator = redColorScaleGenerator ;
300- TableRenderer . defaultProps . tableOptions = { } ;
312+ TableRenderer . defaultProps . tableOptions = { rowTotals : true , colTotals : true } ;
301313 TableRenderer . propTypes . tableColorScaleGenerator = PropTypes . func ;
302314 TableRenderer . propTypes . tableOptions = PropTypes . object ;
303315 return TableRenderer ;
0 commit comments