1- import React , { Component } from 'react' ;
1+ import React from 'react' ;
2+ import PropTypes from 'prop-types' ;
23import './pivottable.css' ;
34
5+
46// helper function for setting row/col-span in pivotTableRenderer
57const spanSize = function ( arr , i , j ) {
68 let x ;
@@ -29,7 +31,7 @@ const spanSize = function(arr, i, j) {
2931 return len ;
3032} ;
3133
32- export default class TableRenderer extends Component {
34+ class TableRenderer extends React . Component {
3335 render ( ) {
3436 const pivotData = this . props . pivotData ;
3537 const colAttrs = pivotData . colAttrs ;
@@ -41,15 +43,15 @@ export default class TableRenderer extends Component {
4143 < table className = "pvtTable" >
4244 < thead >
4345 { colAttrs . map ( function ( c , j ) { return (
44- < tr >
46+ < tr key = { `colAttr ${ j } ` } >
4547 { ( j === 0 && rowAttrs . length !== 0 ) &&
4648 < th colSpan = { rowAttrs . length } rowSpan = { colAttrs . length } />
4749 }
4850 < th className = "pvtAxisLabel" > { c } </ th >
4951 { colKeys . map ( function ( colKey , i ) {
5052 const x = spanSize ( colKeys , i , j ) ;
5153 if ( x === - 1 ) { return null ; }
52- return < th className = "pvtColLabel"
54+ return < th className = "pvtColLabel" key = { `colKey ${ i } ` }
5355 colSpan = { x } rowSpan = { j === colAttrs . length - 1 && rowAttrs . length !== 0 ? 2 : 1 }
5456 >
5557 { colKey [ j ] }
@@ -66,8 +68,8 @@ export default class TableRenderer extends Component {
6668
6769 { ( rowAttrs . length !== 0 ) &&
6870 < tr >
69- { rowAttrs . map ( function ( r ) {
70- return < th className = "pvtAxisLabel" > { r } </ th > ;
71+ { rowAttrs . map ( function ( r , i ) {
72+ return < th className = "pvtAxisLabel" key = { `rowAttr ${ i } ` } > { r } </ th > ;
7173 } ) }
7274 < th className = "pvtTotalLabel" > { colAttrs . length === 0 ? 'Totals' : null } </ th >
7375 </ tr >
@@ -78,17 +80,18 @@ export default class TableRenderer extends Component {
7880 { rowKeys . map ( function ( rowKey , i ) {
7981 const totalAggregator = pivotData . getAggregator ( rowKey , [ ] ) ;
8082 return (
81- < tr >
83+ < tr key = { `rowKeyRow ${ i } ` } >
8284 { rowKey . map ( function ( txt , j ) {
8385 const x = spanSize ( rowKeys , i , j ) ;
8486 if ( x === - 1 ) { return null ; }
85- return < th className = "pvtRowLabel"
87+ return < th key = { `rowKeyLabel ${ i } - ${ j } ` } className = "pvtRowLabel"
8688 rowSpan = { x } colSpan = { j === rowAttrs . length - 1 && colAttrs . length !== 0 ? 2 : 1 }
8789 > { txt } </ th > ;
8890 } ) }
89- { colKeys . map ( function ( colKey ) {
91+ { colKeys . map ( function ( colKey , j ) {
9092 const aggregator = pivotData . getAggregator ( rowKey , colKey ) ;
91- return < td className = "pvtVal" > { aggregator . format ( aggregator . value ( ) ) } </ td > ;
93+ return < td className = "pvtVal" key = { `pvtVal${ i } -${ j } ` } >
94+ { aggregator . format ( aggregator . value ( ) ) } </ td > ;
9295 } ) }
9396 < td className = "pvtTotal" > { totalAggregator . format ( totalAggregator . value ( ) ) } </ td >
9497 </ tr >
@@ -100,9 +103,11 @@ export default class TableRenderer extends Component {
100103 colSpan = { rowAttrs . length + ( colAttrs . length === 0 ? 0 : 1 ) }
101104 > Totals</ th >
102105
103- { colKeys . map ( function ( colKey ) {
106+ { colKeys . map ( function ( colKey , i ) {
104107 const totalAggregator = pivotData . getAggregator ( [ ] , colKey ) ;
105- return < td className = "pvtTotal" > { totalAggregator . format ( totalAggregator . value ( ) ) } </ td > ;
108+ return < td className = "pvtTotal" key = { `total${ i } ` } >
109+ { totalAggregator . format ( totalAggregator . value ( ) ) }
110+ </ td > ;
106111 } ) }
107112
108113 < td className = "pvtGrandTotal" > { grandTotalAggregator . format ( grandTotalAggregator . value ( ) ) } </ td >
@@ -112,3 +117,9 @@ export default class TableRenderer extends Component {
112117 ) ;
113118 }
114119}
120+
121+ TableRenderer . propTypes = {
122+ pivotData : PropTypes . object . isRequired
123+ } ;
124+
125+ export default TableRenderer ;
0 commit comments