@@ -226,7 +226,7 @@ export abstract class IgxBaseExporter {
226226 const childLayoutList = ( grid as IgxHierarchicalGridComponent ) . childLayoutList ;
227227
228228 for ( const island of childLayoutList ) {
229- this . mapHierarchicalGridColumns ( island ) ;
229+ this . mapHierarchicalGridColumns ( island , grid . data [ 0 ] ) ;
230230 }
231231 } else {
232232 this . _ownersMap . set ( DEFAULT_OWNER , columnList ) ;
@@ -597,9 +597,8 @@ export abstract class IgxBaseExporter {
597597
598598 private getAllChildColumnsAndData ( island : IgxRowIslandComponent ,
599599 childData : any [ ] , expansionStateVal : boolean , grid : IgxHierarchicalGridComponent ) {
600- const islandColumnList = island . childColumns . toArray ( ) ;
601- const columnList = this . getColumns ( islandColumnList ) ;
602- const columnHeader = columnList . columns
600+ const columnList = this . _ownersMap . get ( island ) . columns ;
601+ const columnHeader = columnList
603602 . filter ( col => col . headerType === HeaderType . ColumnHeader )
604603 . map ( col => col . header ? col . header : col . field ) ;
605604
@@ -837,7 +836,6 @@ export abstract class IgxBaseExporter {
837836 let lastVisibleColumnIndex = - 1 ;
838837 let maxLevel = 0 ;
839838
840-
841839 columns . forEach ( ( column ) => {
842840 const columnHeader = ! ExportUtilities . isNullOrWhitespaces ( column . header ) ? column . header : column . field ;
843841 const exportColumn = ! column . hidden || this . options . ignoreColumnsVisibility ;
@@ -910,19 +908,74 @@ export abstract class IgxBaseExporter {
910908 return result ;
911909 }
912910
913- private mapHierarchicalGridColumns ( island : IgxRowIslandComponent ) {
914- const islandColumnList = island . childColumns . toArray ( ) ;
915- const columnList = this . getColumns ( islandColumnList ) ;
911+ private mapHierarchicalGridColumns ( island : IgxRowIslandComponent , gridData : any ) {
912+ let columnList : IColumnList ;
913+ let keyData ;
914+
915+ if ( island . autoGenerate ) {
916+ keyData = gridData [ island . key ] ;
917+ const islandKeys = island . children . map ( i => i . key ) ;
918+
919+ const islandData = keyData . map ( i => {
920+ const newItem = { } ;
921+
922+ Object . keys ( i ) . map ( k => {
923+ if ( ! islandKeys . includes ( k ) ) {
924+ newItem [ k ] = i [ k ] ;
925+ }
926+ } ) ;
927+
928+ return newItem ;
929+ } ) ;
930+
931+ columnList = this . getAutoGeneratedColumns ( islandData ) ;
932+ } else {
933+ const islandColumnList = island . childColumns . toArray ( ) ;
934+ columnList = this . getColumns ( islandColumnList ) ;
935+ }
916936
917937 this . _ownersMap . set ( island , columnList ) ;
918938
919939 if ( island . children . length > 0 ) {
920940 for ( const childIsland of island . children ) {
921- this . mapHierarchicalGridColumns ( childIsland ) ;
941+ const islandKeyData = keyData !== undefined ? keyData [ 0 ] : { } ;
942+ this . mapHierarchicalGridColumns ( childIsland , islandKeyData ) ;
922943 }
923944 }
924945 }
925946
947+ private getAutoGeneratedColumns ( data : any [ ] ) {
948+ const colList = [ ] ;
949+ const colWidthList = [ ] ;
950+ const keys = Object . keys ( data [ 0 ] ) ;
951+
952+ keys . forEach ( ( colKey , i ) => {
953+ const columnInfo : IColumnInfo = {
954+ header : colKey ,
955+ field : colKey ,
956+ dataType : 'string' ,
957+ skip : false ,
958+ headerType : HeaderType . ColumnHeader ,
959+ columnSpan : 1 ,
960+ level : 0 ,
961+ startIndex : i ,
962+ pinnedIndex : Number . MAX_VALUE
963+ } ;
964+
965+ colList . push ( columnInfo ) ;
966+ colWidthList . push ( DEFAULT_COLUMN_WIDTH ) ;
967+ } ) ;
968+
969+ const result : IColumnList = {
970+ columns : colList ,
971+ columnWidths : colWidthList ,
972+ indexOfLastPinnedColumn : - 1 ,
973+ maxLevel : 0 ,
974+ } ;
975+
976+ return result ;
977+ }
978+
926979 private resetDefaults ( ) {
927980 this . _sort = null ;
928981 this . flatRecords = [ ] ;
0 commit comments