@@ -644,7 +644,8 @@ export abstract class IgxBaseExporter {
644644 const columnFields = this . _ownersMap . get ( grid ) . columns . map ( col => col . field ) ;
645645
646646 for ( const entry of records ) {
647- const expansionStateVal = grid . expansionStates . has ( entry ) ? grid . expansionStates . get ( entry ) : false ;
647+ const rowKey = grid . primaryKey ? entry [ grid . primaryKey ] : entry ;
648+ const expansionStateVal = grid . expansionStates . has ( rowKey ) ? grid . expansionStates . get ( rowKey ) : grid . getDefaultExpandState ( entry ) ;
648649
649650 const dataWithoutChildren = Object . keys ( entry )
650651 . filter ( k => columnFields . includes ( k ) )
@@ -665,8 +666,8 @@ export abstract class IgxBaseExporter {
665666
666667 for ( const island of childLayoutList ) {
667668 const path : IPathSegment = {
668- rowID : island . primaryKey ? entry [ island . primaryKey ] : entry ,
669- rowKey : island . primaryKey ? entry [ island . primaryKey ] : entry ,
669+ rowID : grid . primaryKey ? entry [ grid . primaryKey ] : entry ,
670+ rowKey : grid . primaryKey ? entry [ grid . primaryKey ] : entry ,
670671 rowIslandKey : island . key
671672 } ;
672673
@@ -805,24 +806,27 @@ export abstract class IgxBaseExporter {
805806 this . flatRecords . push ( exportRecord ) ;
806807
807808 if ( island . children . length > 0 ) {
809+ const islandRowKey = grid ?. primaryKey ? rec [ grid . primaryKey ] : rec ;
808810 const islandExpansionStateVal = grid === undefined ?
809811 false :
810- grid . expansionStates . has ( rec ) ?
811- grid . expansionStates . get ( rec ) :
812+ grid . expansionStates . has ( islandRowKey ) ?
813+ grid . expansionStates . get ( islandRowKey ) :
812814 false ;
813815
814816 for ( const childIsland of island . children ) {
815817 const path : IPathSegment = {
816- rowID : childIsland . primaryKey ? rec [ childIsland . primaryKey ] : rec ,
817- rowKey : childIsland . primaryKey ? rec [ childIsland . primaryKey ] : rec ,
818+ rowID : grid ? .primaryKey ? rec [ grid . primaryKey ] : rec ,
819+ rowKey : grid ? .primaryKey ? rec [ grid . primaryKey ] : rec ,
818820 rowIslandKey : childIsland . key
819821 } ;
820822
821823 // only defined when row is expanded in UI
822824 const childIslandGrid = grid ?. gridAPI . getChildGrid ( [ path ] ) ;
823825 const keyRecordData = this . prepareIslandData ( island , childIslandGrid , rec [ childIsland . key ] ) || [ ] ;
824826
825- this . getAllChildColumnsAndData ( childIsland , keyRecordData , islandExpansionStateVal , childIslandGrid ) ;
827+ // Children should only be visible if both parent and current row are expanded
828+ const combinedExpansionState = expansionStateVal && islandExpansionStateVal ;
829+ this . getAllChildColumnsAndData ( childIsland , keyRecordData , combinedExpansionState , childIslandGrid ) ;
826830 }
827831 }
828832 }
0 commit comments