@@ -128,22 +128,17 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
128128 public navigateTop ( visibleColumnIndex ) {
129129 if ( this . grid . parent !== null ) {
130130 // navigating in child
131- const verticalScroll = this . grid . verticalScrollContainer . getVerticalScroll ( ) ;
132- const cellSelector = this . getCellSelector ( visibleColumnIndex ) ;
133-
134- if ( verticalScroll . scrollTop === 0 ) {
135- this . _focusScrollCellInView ( visibleColumnIndex ) ;
131+ const childContainer = this . grid . nativeElement . parentNode . parentNode ;
132+ const diff =
133+ childContainer . getBoundingClientRect ( ) . top - this . grid . rootGrid . tbody . nativeElement . getBoundingClientRect ( ) . top ;
134+ const topIsVisible = diff >= 0 ;
135+ const scrollable = this . getNextScrollable ( this . grid ) ;
136+ if ( ! topIsVisible ) {
137+ this . scrollGrid ( scrollable . grid , diff ,
138+ ( ) => super . navigateTop ( visibleColumnIndex ) ) ;
136139 } else {
137- this . scrollGrid ( this . grid , 'top' ,
138- ( ) => {
139- const cells = this . grid . nativeElement . querySelectorAll (
140- `${ cellSelector } [data-visibleIndex="${ visibleColumnIndex } "]` ) ;
141- if ( cells . length > 0 ) {
142- this . _focusScrollCellInView ( visibleColumnIndex ) ;
143- }
144- } ) ;
140+ super . navigateTop ( visibleColumnIndex ) ;
145141 }
146-
147142 } else {
148143 super . navigateTop ( visibleColumnIndex ) ;
149144 }
@@ -289,27 +284,13 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
289284 } else {
290285 this . focusNextChildDOMElem ( currentRowEl , this . grid ) ;
291286 }
287+ } else if ( this . grid . parent && this . grid . parent . summariesRowList . length > 0 ) {
288+ this . _navigateToNextParentRow ( currentRowEl ) ;
292289 } else {
293290 this . navigateDown ( currentRowEl , rowIndex , 0 ) ;
294291 }
295292 } else if ( isLastSummaryRow && isLastColumn && this . grid . parent ) {
296- // navigating in child summary, next is parent summary or next parent row
297- const parent = this . grid . parent ;
298- const parentHasSummary = parent . summariesRowList . toArray ( ) . length > 0 ;
299- const parentRowIndex = parseInt (
300- this . getClosestElemByTag ( currentRowEl , 'igx-child-grid-row' ) . parentNode . getAttribute ( 'data-rowindex' ) , 10 ) ;
301- const isLastRowInParent = parent . verticalScrollContainer . igxForOf . length - 1 === parentRowIndex ;
302- // check if next is sibling
303- const childRowContainer = this . getChildGridRowContainer ( this . grid ) ;
304- const nextIsSiblingChild = ! ! childRowContainer . nextElementSibling ;
305- if ( isLastRowInParent && parentHasSummary && ! nextIsSiblingChild ) {
306- // next is parent summary
307- const parentSummary = parent . summariesRowList . toArray ( ) [ 0 ] . nativeElement ;
308- parent . navigation . focusNextRow ( parentSummary , 0 , this . grid . rootGrid , true ) ;
309- } else {
310- // next is sibling or parent
311- this . focusNext ( 0 ) ;
312- }
293+ this . _navigateToNextParentRow ( currentRowEl ) ;
313294 } else if ( isLastDataRow && hasSummaries && isLastColumn && this . grid . parent ) {
314295 // navigating in child rows, next is child grid's summary row
315296 this . focusNextRow ( summaryRows [ 0 ] . nativeElement , 0 , this . grid . parent , true ) ;
@@ -318,6 +299,26 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
318299 }
319300 }
320301
302+ private _navigateToNextParentRow ( currentRowEl : any ) : void {
303+ // next is parent summary or next parent row
304+ const parent = this . grid . parent ;
305+ const parentHasSummary = parent . summariesRowList . length > 0 ;
306+ const parentRowIndex = parseInt (
307+ this . getClosestElemByTag ( currentRowEl , 'igx-child-grid-row' ) . parentNode . getAttribute ( 'data-rowindex' ) , 10 ) ;
308+ const isLastRowInParent = parent . verticalScrollContainer . igxForOf . length - 1 === parentRowIndex ;
309+ // check if next is sibling
310+ const childRowContainer = this . getChildGridRowContainer ( this . grid ) ;
311+ const nextIsSiblingChild = ! ! childRowContainer . nextElementSibling ;
312+ if ( isLastRowInParent && parentHasSummary && ! nextIsSiblingChild ) {
313+ // next is parent summary
314+ const parentSummary = parent . summariesRowList . first . nativeElement ;
315+ parent . navigation . focusNextRow ( parentSummary , 0 , parent , true ) ;
316+ } else {
317+ // next is sibling or parent
318+ this . focusNext ( 0 ) ;
319+ }
320+ }
321+
321322 private focusNextChildDOMElem ( currentRowEl , grid ) {
322323 const gridElem = currentRowEl . nextElementSibling . querySelector ( 'igx-hierarchical-grid' ) ;
323324 const childGridID = gridElem . getAttribute ( 'id' ) ;
@@ -442,31 +443,27 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
442443 childGrid . allowFiltering && childGrid . filterMode === FilterMode . quickFilter ) {
443444 // move to filter cell
444445 childGrid . navigation . moveFocusToFilterCell ( ) ;
446+ } else if ( childGrid . rowList . length === 0 ) {
447+ // move to prev child or parent row
448+ const prevChild = this . getSibling ( childGrid ) ;
449+ if ( prevChild ) {
450+ this . performShiftTabIntoChild ( prevChild , currentRowEl , rowIndex ) ;
451+ } else {
452+ this . navigateUp ( currentRowEl , rowIndex ,
453+ this . grid . unpinnedColumns [ this . grid . unpinnedColumns . length - 1 ] . visibleIndex ) ;
454+ }
445455 } else {
446- // move to next cell
447- this . navigateUp ( currentRowEl , rowIndex , lastIndex ) ;
456+ // move to prev cell
457+ childGrid . navigation . goToLastCell ( ) ;
448458 }
449459 }
450460
451- private _focusScrollCellInView ( visibleColumnIndex ) {
452- const cellSelector = this . getCellSelector ( visibleColumnIndex ) ;
453- const cells = this . grid . nativeElement . querySelectorAll (
454- `${ cellSelector } [data-visibleIndex="${ visibleColumnIndex } "]` ) ;
455- const cell = cells [ 0 ] ;
456- const childContainer = this . grid . nativeElement . parentNode . parentNode ;
457- const scrTop = this . grid . parent . verticalScrollContainer . getVerticalScroll ( ) . scrollTop ;
458- const maxScroll = this . grid . parent . verticalScrollContainer . getVerticalScroll ( ) . scrollHeight - this . grid . parent . calcHeight ;
459- const dc = childContainer . parentNode . parentNode ;
460- const scrWith = parseInt ( dc . style . top , 10 ) ;
461- const parentRowOffset = childContainer . parentNode . offsetTop + this . grid . nativeElement . offsetTop +
462- scrWith ;
463- if ( ( scrTop === 0 && parentRowOffset < 0 ) || parentRowOffset === 0 || ( scrTop === maxScroll && parentRowOffset > 0 ) ) {
464- // cell is in view
465- cell . focus ( { preventScroll : true } ) ;
466- } else {
467- // scroll parent so that cell is in view
468- this . scrollGrid ( this . grid . parent , parentRowOffset , ( ) => cell . focus ( { preventScroll : true } ) ) ;
461+ private getSibling ( childGrid ) {
462+ const prevChildRow = childGrid . childRow . nativeElement . previousElementSibling ;
463+ if ( prevChildRow ) {
464+ return prevChildRow . children [ 0 ] . children [ 0 ] ;
469465 }
466+ return null ;
470467 }
471468
472469 private focusNextChild ( elem , visibleColumnIndex , grid ) {
@@ -590,14 +587,17 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
590587 const nextIsSiblingChild = ! ! childRowContainer . nextElementSibling ;
591588 let next = childRowContainer . nextElementSibling || nextParentElem ;
592589 const verticalScroll = nextParentGrid . verticalScrollContainer . getVerticalScroll ( ) ;
590+ const parentState = nextParentGrid . verticalScrollContainer . state ;
591+ const atLastChunk = parentState . startIndex + parentState . chunkSize ===
592+ nextParentGrid . verticalScrollContainer . igxForOf . length ;
593593 if ( next ) {
594594 if ( nextIsSiblingChild ) {
595595 this . focusNextChild ( next , visibleColumnIndex , nextParentGrid ) ;
596596 } else {
597597 this . focusNextRow ( next , visibleColumnIndex , grid || nextParentGrid ) ;
598598 }
599599 } else if ( verticalScroll . scrollTop !==
600- verticalScroll . scrollHeight - nextParentGrid . verticalScrollContainer . igxForContainerSize ) {
600+ verticalScroll . scrollHeight - nextParentGrid . verticalScrollContainer . igxForContainerSize && ! atLastChunk ) {
601601 this . scrollGrid ( nextParentGrid , 'next' ,
602602 ( ) => {
603603 nextParentElem = parentInfo . nextElement ;
@@ -717,7 +717,12 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
717717 grid . parentVirtDir . onChunkLoad
718718 . pipe ( first ( ) )
719719 . subscribe ( callBackFunc ) ;
720- grid . dataRowList . toArray ( ) [ 0 ] . virtDirRow . scrollTo ( unpinnedIndex ) ;
720+ if ( grid . dataRowList . length > 0 ) {
721+ grid . dataRowList . first . virtDirRow . scrollTo ( unpinnedIndex ) ;
722+ } else {
723+ grid . headerContainer . scrollTo ( unpinnedIndex ) ;
724+ }
725+
721726 }
722727 private scrollGrid ( grid , target , callBackFunc ) {
723728 this . getFocusableGrid ( ) . nativeElement . focus ( { preventScroll : true } ) ;
0 commit comments