@@ -61,21 +61,27 @@ function makeRenderer(opts = {}) {
61
61
const rowKeys = pivotData . getRowKeys ( ) ;
62
62
const colKeys = pivotData . getColKeys ( ) ;
63
63
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 ;
64
67
65
68
let valueCellColors = ( ) => { } ;
66
69
let rowTotalColors = ( ) => { } ;
67
70
let colTotalColors = ( ) => { } ;
68
71
if ( opts . heatmapMode ) {
69
72
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
+ }
79
85
if ( opts . heatmapMode === 'full' ) {
80
86
const allValues = [ ] ;
81
87
rowKeys . map ( r =>
@@ -164,7 +170,7 @@ function makeRenderer(opts = {}) {
164
170
) ;
165
171
} ) }
166
172
167
- { j === 0 && (
173
+ { j === 0 && rowTotals && (
168
174
< th
169
175
className = "pvtTotalLabel"
170
176
rowSpan = {
@@ -239,55 +245,61 @@ function makeRenderer(opts = {}) {
239
245
</ td >
240
246
) ;
241
247
} ) }
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
+ ) }
252
260
</ tr >
253
261
) ;
254
262
} ) }
255
263
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 && (
267
291
< td
268
- className = "pvtTotal"
269
- key = { `total${ i } ` }
270
292
onClick = {
271
293
getClickHandler &&
272
- getClickHandler ( totalAggregator . value ( ) , [ null ] , colKey )
294
+ getClickHandler ( grandTotalAggregator . value ( ) , [ null ] , [ null ] )
273
295
}
274
- style = { rowTotalColors ( totalAggregator . value ( ) ) }
296
+ className = "pvtGrandTotal"
275
297
>
276
- { totalAggregator . format ( totalAggregator . value ( ) ) }
298
+ { grandTotalAggregator . format ( grandTotalAggregator . value ( ) ) }
277
299
</ 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
+ ) }
291
303
</ tbody >
292
304
</ table >
293
305
) ;
@@ -297,7 +309,7 @@ function makeRenderer(opts = {}) {
297
309
TableRenderer . defaultProps = PivotData . defaultProps ;
298
310
TableRenderer . propTypes = PivotData . propTypes ;
299
311
TableRenderer . defaultProps . tableColorScaleGenerator = redColorScaleGenerator ;
300
- TableRenderer . defaultProps . tableOptions = { } ;
312
+ TableRenderer . defaultProps . tableOptions = { rowTotals : true , colTotals : true } ;
301
313
TableRenderer . propTypes . tableColorScaleGenerator = PropTypes . func ;
302
314
TableRenderer . propTypes . tableOptions = PropTypes . object ;
303
315
return TableRenderer ;
0 commit comments