@@ -55,7 +55,7 @@ export default Base =>
55
55
columnsWithExpander = [ expanderColumn , ...columnsWithExpander ]
56
56
}
57
57
58
- const makeDecoratedColumn = column => {
58
+ const makeDecoratedColumn = ( column , parentColumn ) => {
59
59
let dcol
60
60
if ( column . expander ) {
61
61
dcol = {
@@ -70,44 +70,51 @@ export default Base =>
70
70
}
71
71
}
72
72
73
+ // Ensure minWidth is not greater than maxWidth if set
74
+ if ( dcol . maxWidth < dcol . minWidth ) {
75
+ dcol . minWidth = dcol . maxWidth
76
+ }
77
+
78
+ if ( parentColumn ) {
79
+ dcol . parentColumn = parentColumn
80
+ }
81
+
82
+ // First check for string accessor
73
83
if ( typeof dcol . accessor === 'string' ) {
74
84
dcol . id = dcol . id || dcol . accessor
75
85
const accessorString = dcol . accessor
76
86
dcol . accessor = row => _ . get ( row , accessorString )
77
87
return dcol
78
88
}
79
89
90
+ // Fall back to functional accessor (but require an ID)
80
91
if ( dcol . accessor && ! dcol . id ) {
81
92
console . warn ( dcol )
82
93
throw new Error (
83
94
'A column id is required if using a non-string accessor for column above.'
84
95
)
85
96
}
86
97
98
+ // Fall back to an undefined accessor
87
99
if ( ! dcol . accessor ) {
88
100
dcol . accessor = d => undefined
89
101
}
90
102
91
- // Ensure minWidth is not greater than maxWidth if set
92
- if ( dcol . maxWidth < dcol . minWidth ) {
93
- dcol . minWidth = dcol . maxWidth
94
- }
95
-
96
103
return dcol
97
104
}
98
105
99
106
// Decorate the columns
100
- const decorateAndAddToAll = col => {
101
- const decoratedColumn = makeDecoratedColumn ( col )
107
+ const decorateAndAddToAll = ( column , parentColumn ) => {
108
+ const decoratedColumn = makeDecoratedColumn ( column , parentColumn )
102
109
allDecoratedColumns . push ( decoratedColumn )
103
110
return decoratedColumn
104
111
}
105
- let allDecoratedColumns = [ ]
112
+ const allDecoratedColumns = [ ]
106
113
const decoratedColumns = columnsWithExpander . map ( ( column , i ) => {
107
114
if ( column . columns ) {
108
115
return {
109
116
...column ,
110
- columns : column . columns . map ( decorateAndAddToAll ) ,
117
+ columns : column . columns . map ( d => decorateAndAddToAll ( d , column ) ) ,
111
118
}
112
119
} else {
113
120
return decorateAndAddToAll ( column )
@@ -156,8 +163,17 @@ export default Base =>
156
163
}
157
164
} )
158
165
166
+ let PivotParentColumn = pivotColumns . reduce (
167
+ ( prev , current ) =>
168
+ prev && prev === current . parentColumn && current . parentColumn ,
169
+ pivotColumns [ 0 ] . parentColumn
170
+ )
171
+
172
+ let PivotGroupHeader = hasHeaderGroups && PivotParentColumn . Header
173
+ PivotGroupHeader = PivotGroupHeader || ( ( ) => < strong > Pivoted</ strong > )
174
+
159
175
let pivotColumnGroup = {
160
- header : ( ) => < strong > Group </ strong > ,
176
+ Header : PivotGroupHeader ,
161
177
columns : pivotColumns . map ( col => ( {
162
178
...this . props . pivotDefaults ,
163
179
...col ,
0 commit comments