@@ -114,19 +114,19 @@ export const NeoTableChart = (props: ChartProps) => {
114
114
const actionableFields = actionsRules . map ( ( r ) => r . field ) ;
115
115
116
116
const columns = transposed
117
- ? [ 'Field' ] . concat ( records . map ( ( r , j ) => `Value ${ j == 0 ? '' : ` ${ ( j + 1 ) . toString ( ) } ` } ` ) ) . map ( ( key , i ) => {
118
- const value = key ;
117
+ ? [ records [ 0 ] . keys [ 0 ] ] . concat ( records . map ( ( record ) => record . _fields [ 0 ] ? .toString ( ) || '' ) ) . map ( ( key , i ) => {
118
+ const uniqueKey = ` ${ String ( key ) } _ ${ i } ` ;
119
119
return ApplyColumnType (
120
120
{
121
121
key : `col-key-${ i } ` ,
122
- field : generateSafeColumnKey ( key ) ,
122
+ field : generateSafeColumnKey ( uniqueKey ) ,
123
123
headerName : generateSafeColumnKey ( key ) ,
124
124
headerClassName : 'table-small-header' ,
125
125
disableColumnSelector : true ,
126
126
flex : columnWidths && i < columnWidths . length ? columnWidths [ i ] : 1 ,
127
127
disableClickEventBubbling : true ,
128
128
} ,
129
- value ,
129
+ key ,
130
130
actionableFields . includes ( key )
131
131
) ;
132
132
} )
@@ -166,15 +166,32 @@ export const NeoTableChart = (props: ChartProps) => {
166
166
...columns . filter ( ( x ) => x . field . startsWith ( HIDDEN_COLUMN_PREFIX ) ) . map ( ( x ) => ( { [ x . field ] : false } ) )
167
167
) ;
168
168
169
+ const getTransposedRows = ( records ) => {
170
+ // Skip first key
171
+ const rowKeys = [ ...records [ 0 ] . keys ] ;
172
+ rowKeys . shift ( ) ;
173
+
174
+ // Add values in rows
175
+ const rowsWithValues = rowKeys . map ( ( key , i ) =>
176
+ Object . assign (
177
+ { id : i , Field : key } ,
178
+ ...records . map ( ( record , j ) => ( {
179
+ [ `${ record . _fields [ 0 ] } _${ j + 1 } ` ] : RenderSubValue ( record . _fields [ i + 1 ] ) ,
180
+ } ) )
181
+ )
182
+ ) ;
183
+
184
+ // Add field in rows
185
+ const rowsWithFieldAndValues = rowsWithValues . map ( ( row , i ) => ( {
186
+ ...row ,
187
+ [ `${ records [ 0 ] . keys [ 0 ] } _${ 0 } ` ] : rowKeys [ i ] ,
188
+ } ) ) ;
189
+
190
+ return rowsWithFieldAndValues ;
191
+ } ;
192
+
169
193
const rows = transposed
170
- ? records [ 0 ] . keys . map ( ( key , i ) => {
171
- return Object . assign (
172
- { id : i , Field : key } ,
173
- ...records . map ( ( r , j ) => ( {
174
- [ `Value${ j == 0 ? '' : ` ${ ( j + 1 ) . toString ( ) } ` } ` ] : RenderSubValue ( r . _fields [ i ] ) ,
175
- } ) )
176
- ) ;
177
- } )
194
+ ? getTransposedRows ( records )
178
195
: records . map ( ( record , rownumber ) => {
179
196
return Object . assign (
180
197
{ id : rownumber } ,
0 commit comments