-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring filter cell navigation so that it is handled in the navigation service. Handling special scenarios for hierarchical grid in the hierarchical navigation service. #4267
Changes from 3 commits
e6ed866
2069c97
801cf17
232f288
9b2f44d
819893e
63850ee
87ba131
920a087
9f41f58
14f8255
ea54720
c9a6930
0a49c18
3b0b1ec
8e0de99
02e234b
b939adb
ef225f2
be06b88
120014e
22d1407
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { IgxGridBaseComponent } from './grid-base.component'; | ||
import { first } from 'rxjs/operators'; | ||
import { IgxColumnComponent } from './column.component'; | ||
import { IgxColumnComponent, IgxColumnGroupComponent } from './column.component'; | ||
import { IgxGridGroupByRowComponent } from './grid/groupby-row.component'; | ||
|
||
enum MoveDirection { | ||
LEFT = 'left', | ||
|
@@ -456,15 +457,68 @@ export class IgxGridNavigationService { | |
} | ||
} | ||
|
||
public moveFocusToFilterCell() { | ||
public moveFocusToFilterCell(toStart?: boolean) { | ||
const columns = this.grid.filteringService.unpinnedFilterableColumns; | ||
if (this.isColumnFullyVisible(columns.length - 1)) { | ||
this.grid.filteringService.focusFilterCellChip(columns[columns.length - 1], false); | ||
const targetIndex = toStart ? 0 : columns.length - 1; | ||
const isVisible = toStart ? this.isColumnLeftFullyVisible(targetIndex) : this.isColumnFullyVisible(targetIndex); | ||
if (isVisible) { | ||
this.grid.filteringService.focusFilterCellChip(columns[targetIndex], false); | ||
} else { | ||
this.grid.filteringService.scrollToFilterCell(columns[columns.length - 1], false); | ||
this.grid.filteringService.scrollToFilterCell(columns[targetIndex], false); | ||
} | ||
} | ||
|
||
public navigatePrevFilterCell(column: IgxColumnComponent, eventArgs) { | ||
const cols = this.grid.filteringService.unpinnedFilterableColumns; | ||
const prevFilterableIndex = cols.indexOf(column) - 1; | ||
const prevIndex = cols[prevFilterableIndex].visibleIndex; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
const visibleIndex = column.visibleIndex; | ||
|
||
if (prevIndex >= 0 && visibleIndex > 0 && !this.isColumnLeftFullyVisible(prevIndex) && !column.pinned) { | ||
eventArgs.preventDefault(); | ||
this.grid.filteringService.scrollToFilterCell(cols[prevIndex], false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If visible index is used for the |
||
} else if (column.visibleIndex === 0 || | ||
(prevIndex < 0 && !this.getFirstPinnedFilterableColumn()) || | ||
column === this.getFirstPinnedFilterableColumn()) { | ||
eventArgs.preventDefault(); | ||
} | ||
} | ||
|
||
public navigateNextFilterCell(column: IgxColumnComponent, eventArgs) { | ||
skrustev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const cols = this.grid.filteringService.unpinnedFilterableColumns; | ||
const nextIndex = cols.indexOf(column) + 1; | ||
if (column === this.getLastPinnedFilterableColumn() && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please format this code |
||
!this.isColumnFullyVisible(nextIndex)) { | ||
this.grid.filteringService.scrollToFilterCell(cols[nextIndex], false); | ||
eventArgs.stopPropagation(); | ||
return; | ||
} | ||
|
||
if (nextIndex >= this.grid.filteringService.unpinnedFilterableColumns.length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the 'cols' variable here. |
||
if (!this.grid.filteringService.grid.filteredData || this.grid.filteringService.grid.filteredData.length > 0) { | ||
if (this.grid.filteringService.grid.rowList.filter(row => row instanceof IgxGridGroupByRowComponent).length > 0) { | ||
eventArgs.stopPropagation(); | ||
return; | ||
} | ||
this.goToFirstCell(); | ||
} | ||
eventArgs.preventDefault(); | ||
} else if (!column.pinned && !this.isColumnFullyVisible(nextIndex)) { | ||
eventArgs.preventDefault(); | ||
this.grid.filteringService.scrollToFilterCell(this.grid.filteringService.unpinnedFilterableColumns[nextIndex], true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the 'cols' variable here. |
||
} | ||
} | ||
|
||
private getLastPinnedFilterableColumn(): IgxColumnComponent { | ||
const pinnedFilterableColums = | ||
this.grid.pinnedColumns.filter(col => !(col instanceof IgxColumnGroupComponent) && col.filterable); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Columns and column groups have a getter for this check: |
||
return pinnedFilterableColums[pinnedFilterableColums.length - 1]; | ||
} | ||
|
||
private getFirstPinnedFilterableColumn(): IgxColumnComponent { | ||
return this.grid.pinnedColumns.filter(col => !(col instanceof IgxColumnGroupComponent) && col.filterable)[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
} | ||
|
||
public performShiftTabKey(currentRowEl, rowIndex, visibleColumnIndex, isSummary = false) { | ||
if (visibleColumnIndex === 0) { | ||
if (this.isRowInEditMode(rowIndex)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { IgxGridNavigationService } from '../grid-navigation.service'; | ||
import { IgxHierarchicalGridComponent } from './hierarchical-grid.component'; | ||
import { first } from 'rxjs/operators'; | ||
import { IgxColumnComponent, FilterMode } from '../grid'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong import! Either import them from the respective files or explicitly import from the barrel file |
||
|
||
export class IgxHierarchicalGridNavigationService extends IgxGridNavigationService { | ||
public grid: IgxHierarchicalGridComponent; | ||
|
@@ -227,16 +228,63 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi | |
} | ||
|
||
public performTab(currentRowEl, rowIndex, visibleColumnIndex) { | ||
if (!this.grid.rowList.find(row => row.index === rowIndex + 1) && this.grid.parent && | ||
this.grid.unpinnedColumns[this.grid.unpinnedColumns.length - 1].visibleIndex === visibleColumnIndex) { | ||
const isLastColumn = this.grid.unpinnedColumns[this.grid.unpinnedColumns.length - 1].visibleIndex === visibleColumnIndex; | ||
const nextIndex = rowIndex + 1; | ||
const virt = this.grid.verticalScrollContainer; | ||
const isNextChild = nextIndex <= virt.igxForOf.length - 1 && | ||
this.grid.isChildGridRecord(virt.igxForOf[nextIndex]); | ||
if (!this.grid.rowList.find(row => row.index === rowIndex + 1) && this.grid.parent && | ||
this.grid.unpinnedColumns[this.grid.unpinnedColumns.length - 1].visibleIndex === visibleColumnIndex) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that not the same check as line 231? |
||
const childContainer = this.getChildGridRowContainer(); | ||
const nextIsSiblingChild = this.grid.parent ? !!childContainer.nextElementSibling : false; | ||
if (nextIsSiblingChild) { | ||
this.focusNextChildDOMElem(childContainer, this.grid.parent); | ||
return; | ||
} | ||
this.navigateDown(currentRowEl, rowIndex, 0); | ||
} else if (isLastColumn && isNextChild) { | ||
const isInView = virt.state.startIndex + virt.state.chunkSize > nextIndex; | ||
if (!isInView) { | ||
this.scrollGrid(this.grid, 'next', () => { | ||
this.focusNextChildDOMElem(currentRowEl, this.grid); | ||
}); | ||
} else { | ||
this.focusNextChildDOMElem(currentRowEl, this.grid); | ||
} | ||
} else { | ||
super.performTab(currentRowEl, rowIndex, visibleColumnIndex); | ||
} | ||
} | ||
|
||
private focusNextChildDOMElem(currentRowEl, grid) { | ||
const gridElem = currentRowEl.nextElementSibling.querySelector('igx-hierarchical-grid'); | ||
const childGridID = gridElem.getAttribute('id'); | ||
const childGrid = this.getChildGrid(childGridID, grid); | ||
if (childGrid.allowFiltering && childGrid.filterMode === FilterMode.quickFilter) { | ||
childGrid.navigation.moveFocusToFilterCell(true); | ||
return; | ||
} | ||
this.focusNextChild(currentRowEl.nextElementSibling, 0, grid); | ||
} | ||
|
||
public navigatePrevFilterCell(column: IgxColumnComponent, eventArgs) { | ||
if (column.visibleIndex === 0 && this.grid.parent) { | ||
eventArgs.preventDefault(); | ||
let targetGrid = this.grid.parent; | ||
const prevSiblingChild = this.getChildGridRowContainer().previousElementSibling; | ||
if (prevSiblingChild) { | ||
const gridElem = prevSiblingChild.querySelectorAll('igx-hierarchical-grid')[0]; | ||
targetGrid = this.getChildGrid(gridElem.getAttribute('id'), this.grid.parent); | ||
} | ||
this.focusPrev(targetGrid.unpinnedColumns[targetGrid.unpinnedColumns.length - 1].visibleIndex); | ||
} else { | ||
super.navigatePrevFilterCell(column, eventArgs); | ||
} | ||
} | ||
|
||
public performShiftTabKey(currentRowEl, rowIndex, visibleColumnIndex) { | ||
if (visibleColumnIndex === 0 && rowIndex === 0 && this.grid.parent) { | ||
if (this.grid.allowFiltering) { | ||
if (this.grid.allowFiltering && this.grid.filterMode === FilterMode.quickFilter) { | ||
this.moveFocusToFilterCell(); | ||
} else { | ||
const prevSiblingChild = this.getChildGridRowContainer().previousElementSibling; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isColumnFullyVisible()
takes visible index and index from theunpinnedFilterableColumns
collection wouldn't work in some scenarios.