From 03b5771e8e5c0eaf646f5b63955fdef1ed292bd2 Mon Sep 17 00:00:00 2001 From: Diyan Dimitrov Date: Mon, 14 Jan 2019 12:06:26 +0200 Subject: [PATCH] feat(search): fixing tree grid search highlight #3519 --- .../src/lib/grids/grid-base.component.ts | 37 ++++++++---- .../grids/tree-grid/tree-grid-api.service.ts | 27 +++++++-- .../grids/tree-grid/tree-grid.component.ts | 57 +++++++++++++++++++ .../lib/grids/tree-grid/tree-grid.pipes.ts | 14 +++-- .../grid-search-box.component.css | 4 -- .../grid-search-box.component.html | 6 +- .../tree-grid-flat-data.sample.html | 5 ++ src/app/tree-grid/tree-grid.sample.html | 6 +- 8 files changed, 128 insertions(+), 28 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts index 7ddb1603afe..57e74f62f97 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts @@ -4186,16 +4186,19 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements if (this.lastSearchInfo.matchInfoCache.length) { const matchInfo = this.lastSearchInfo.matchInfoCache[this.lastSearchInfo.activeMatchIndex]; - IgxTextHighlightDirective.setActiveHighlight(this.id, { - columnIndex: matchInfo.column, - rowIndex: matchInfo.row, - index: matchInfo.index, - page: matchInfo.page - }); - if (scroll !== false) { this.scrollTo(matchInfo.row, matchInfo.column, matchInfo.page, matchInfo.groupByRecord); } + + const fixedMatchInfo = this.fixMatchInfoIndexes(matchInfo); + + IgxTextHighlightDirective.setActiveHighlight(this.id, { + columnIndex: fixedMatchInfo.column, + rowIndex: fixedMatchInfo.row, + index: fixedMatchInfo.index, + page: fixedMatchInfo.page + }); + } else { IgxTextHighlightDirective.clearActiveHighlight(this.id); } @@ -4203,6 +4206,13 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements return this.lastSearchInfo.matchInfoCache.length; } + /** + * @hidden + */ + protected fixMatchInfoIndexes(matchInfo: any): any { + return matchInfo; + } + /** * Returns an array containing the filtered data. * ```typescript @@ -4338,13 +4348,11 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements const groupByRecord = groupByRecords ? groupByRecords[i] : null; const groupByIncrement = groupIndexData ? groupIndexData[i] : 0; const pagingIncrement = this.getPagingIncrement(groupByIncrement, groupIndexData, Math.floor(i / this.perPage)); - let rowIndex = this.paging ? (i % this.perPage) + pagingIncrement : i + groupByIncrement; if (this.paging && i % this.perPage === 0) { collapsedRowsCount = 0; } - - rowIndex -= collapsedRowsCount; + const rowIndex = this.resolveSearchRowIndex(i, pagingIncrement, groupByIncrement, collapsedRowsCount); if (groupByRecord && !this.isExpandedGroup(groupByRecord)) { collapsedRowsCount++; @@ -4389,6 +4397,15 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements }); } + /** + * @hidden + */ + protected resolveSearchRowIndex(index: number, pagingIncrement: number, groupByIncrement: number, collapsedRowsCount: number) { + let rowIndex = this.paging ? (index % this.perPage) + pagingIncrement : index + groupByIncrement; + rowIndex -= collapsedRowsCount; + return rowIndex; + } + /** * @hidden */ diff --git a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-api.service.ts b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-api.service.ts index e0058f34d7e..2be1838f8b4 100644 --- a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-api.service.ts +++ b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-api.service.ts @@ -58,7 +58,7 @@ export class IgxTreeGridAPIService extends GridBaseAPIService 0) { this.setIndentationLevels(id, record.children, indentationLevel + 1); @@ -107,7 +107,7 @@ export class IgxTreeGridHierarchizingPipe implements PipeTransform { parent: parent, level: indentationLevel }; - record.expanded = this.gridAPI.get_row_expansion_state(id, record.rowID, record.level); + record.expanded = this.gridAPI.get_row_expansion_state(id, record); flatData.push(item); map.set(record.rowID, record); record.children = item[childDataKey] ? @@ -138,17 +138,20 @@ export class IgxTreeGridFlatteningPipe implements PipeTransform { expandedLevels: number, expandedStates: Map, pipeTrigger: number): any[] { const grid: IgxTreeGridComponent = this.gridAPI.get(id); - const data: any[] = []; + const data: ITreeGridRecord[] = []; grid.processedRootRecords = collection; grid.processedRecords = new Map(); + grid.processedFlatData = []; this.getFlatDataRecursive(collection, data, expandedLevels, expandedStates, id, true); + grid.processedExpandedFlatData = data.map(r => r.data); + return data; } - private getFlatDataRecursive(collection: ITreeGridRecord[], data: any[], + private getFlatDataRecursive(collection: ITreeGridRecord[], data: ITreeGridRecord[], expandedLevels: number, expandedStates: Map, gridID: string, parentExpanded: boolean) { if (!collection || !collection.length) { @@ -164,11 +167,12 @@ export class IgxTreeGridFlatteningPipe implements PipeTransform { } hierarchicalRecord.expanded = this.gridAPI.get_row_expansion_state(gridID, - hierarchicalRecord.rowID, hierarchicalRecord.level); + hierarchicalRecord); this.updateNonProcessedRecordExpansion(grid, hierarchicalRecord); grid.processedRecords.set(hierarchicalRecord.rowID, hierarchicalRecord); + grid.processedFlatData.push(hierarchicalRecord.data); this.getFlatDataRecursive(hierarchicalRecord.children, data, expandedLevels, expandedStates, gridID, parentExpanded && hierarchicalRecord.expanded); diff --git a/src/app/grid-search-box/grid-search-box.component.css b/src/app/grid-search-box/grid-search-box.component.css index 2fece2fbafa..05a72a3cfac 100644 --- a/src/app/grid-search-box/grid-search-box.component.css +++ b/src/app/grid-search-box/grid-search-box.component.css @@ -1,7 +1,3 @@ -.offset { - margin-bottom: 15px; -} - .resultsText { font-size: 0.875rem; } diff --git a/src/app/grid-search-box/grid-search-box.component.html b/src/app/grid-search-box/grid-search-box.component.html index c0a8981e3cb..ce2f5013283 100644 --- a/src/app/grid-search-box/grid-search-box.component.html +++ b/src/app/grid-search-box/grid-search-box.component.html @@ -1,4 +1,4 @@ - + search clear @@ -21,10 +21,10 @@
- Case Sensitive + Aa - Exact Match + Ab
diff --git a/src/app/tree-grid-flat-data/tree-grid-flat-data.sample.html b/src/app/tree-grid-flat-data/tree-grid-flat-data.sample.html index 08e21311954..ddfaf1ff574 100644 --- a/src/app/tree-grid-flat-data/tree-grid-flat-data.sample.html +++ b/src/app/tree-grid-flat-data/tree-grid-flat-data.sample.html @@ -11,6 +11,7 @@
+ + + + +
diff --git a/src/app/tree-grid/tree-grid.sample.html b/src/app/tree-grid/tree-grid.sample.html index e65c7b70221..7a6618857b7 100644 --- a/src/app/tree-grid/tree-grid.sample.html +++ b/src/app/tree-grid/tree-grid.sample.html @@ -11,8 +11,6 @@
- - + + + +