Skip to content

Commit 50e7d85

Browse files
MKirovaMKirova
authored andcommitted
chore(*): When searching, mark merged cells as a single result.
1 parent 190f29d commit 50e7d85

File tree

3 files changed

+89
-13
lines changed

3 files changed

+89
-13
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { IgcTrialWatermark } from 'igniteui-trial-watermark';
3838
import { Subject, pipe, fromEvent, animationFrameScheduler, merge } from 'rxjs';
3939
import { takeUntil, first, filter, throttleTime, map, shareReplay, takeWhile } from 'rxjs/operators';
4040
import { cloneArray, mergeObjects, compareMaps, resolveNestedPath, isObject, PlatformUtil } from '../core/utils';
41-
import { GridColumnDataType } from '../data-operations/data-util';
41+
import { DataUtil, GridColumnDataType } from '../data-operations/data-util';
4242
import { FilteringLogic } from '../data-operations/filtering-expression.interface';
4343
import { IGroupByRecord } from '../data-operations/groupby-record.interface';
4444
import { IForOfDataChangeEventArgs, IgxGridForOfDirective } from '../directives/for-of/for_of.directive';
@@ -3911,10 +3911,12 @@ export abstract class IgxGridBaseDirective implements GridType,
39113911

39123912
this.activeNodeChange.pipe(filter(() => !this._init), destructor).subscribe(() => {
39133913
this._activeRowIndexes = null;
3914+
this.refreshSearch();
39143915
});
39153916

39163917
this.selectionService.selectedRangeChange.pipe(filter(() => !this._init), destructor).subscribe(() => {
39173918
this._activeRowIndexes = null;
3919+
this.refreshSearch();
39183920
});
39193921
}
39203922

@@ -7977,25 +7979,29 @@ export abstract class IgxGridBaseDirective implements GridType,
79777979
const caseSensitive = this._lastSearchInfo.caseSensitive;
79787980
const exactMatch = this._lastSearchInfo.exactMatch;
79797981
const searchText = caseSensitive ? this._lastSearchInfo.searchText : this._lastSearchInfo.searchText.toLowerCase();
7980-
const data = this.filteredSortedData;
7982+
let data = this.filteredSortedData;
7983+
if (this.hasCellsToMerge) {
7984+
data = DataUtil.merge(cloneArray(this.filteredSortedData), this.columnsToMerge, this.mergeStrategy, this.activeRowIndexes, this);
7985+
}
79817986
const columnItems = this.visibleColumns.filter((c) => !c.columnGroup).sort((c1, c2) => c1.visibleIndex - c2.visibleIndex);
79827987
const columnsPathParts = columnItems.map(col => columnFieldPath(col.field));
79837988

79847989
data.forEach((dataRow, rowIndex) => {
7990+
const currentRowData = this.isRecordMerged(dataRow) ? dataRow.recordRef : dataRow;
79857991
columnItems.forEach((c, cid) => {
79867992
const pipeArgs = this.getColumnByName(c.field).pipeArgs;
7987-
const value = c.formatter ? c.formatter(resolveNestedPath(dataRow, columnsPathParts[cid]), dataRow) :
7988-
c.dataType === 'number' ? formatNumber(resolveNestedPath(dataRow, columnsPathParts[cid]) as number, this.locale, pipeArgs.digitsInfo) :
7993+
const value = c.formatter ? c.formatter(resolveNestedPath(currentRowData, columnsPathParts[cid]), currentRowData) :
7994+
c.dataType === 'number' ? formatNumber(resolveNestedPath(currentRowData, columnsPathParts[cid]) as number, this.locale, pipeArgs.digitsInfo) :
79897995
c.dataType === 'date'
7990-
? formatDate(resolveNestedPath(dataRow, columnsPathParts[cid]) as string, pipeArgs.format, this.locale, pipeArgs.timezone)
7991-
: resolveNestedPath(dataRow, columnsPathParts[cid]);
7996+
? formatDate(resolveNestedPath(currentRowData, columnsPathParts[cid]) as string, pipeArgs.format, this.locale, pipeArgs.timezone)
7997+
: resolveNestedPath(currentRowData, columnsPathParts[cid]);
79927998
if (value !== undefined && value !== null && c.searchable) {
79937999
let searchValue = caseSensitive ? String(value) : String(value).toLowerCase();
7994-
8000+
const isMergePlaceHolder = this.isRecordMerged(dataRow) ? !!dataRow?.cellMergeMeta.get(c.field)?.root : false;
79958001
if (exactMatch) {
7996-
if (searchValue === searchText) {
8002+
if (searchValue === searchText && !isMergePlaceHolder) {
79978003
const mic: IMatchInfoCache = {
7998-
row: dataRow,
8004+
row: currentRowData,
79998005
column: c.field,
80008006
index: 0,
80018007
metadata: new Map<string, boolean>([['pinned', this.isRecordPinnedByIndex(rowIndex)]])
@@ -8007,9 +8013,9 @@ export abstract class IgxGridBaseDirective implements GridType,
80078013
let occurrenceIndex = 0;
80088014
let searchIndex = searchValue.indexOf(searchText);
80098015

8010-
while (searchIndex !== -1) {
8016+
while (searchIndex !== -1 && !isMergePlaceHolder) {
80118017
const mic: IMatchInfoCache = {
8012-
row: dataRow,
8018+
row: currentRowData,
80138019
column: c.field,
80148020
index: occurrenceIndex++,
80158021
metadata: new Map<string, boolean>([['pinned', this.isRecordPinnedByIndex(rowIndex)]])

src/app/grid-cellMerging/grid-cellMerging.component.html

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
<h4 class="sample-title">Grid with cell merge</h4>
2-
<igx-grid [data]="data" width="800px" height="550px" [moving]="true"
2+
3+
<div class="grid__wrapper">
4+
<igx-input-group type="search" class="offset">
5+
<igx-prefix>
6+
@if (searchText.length === 0) {
7+
<igx-icon>search</igx-icon>
8+
}
9+
@if (searchText.length > 0) {
10+
<igx-icon (click)="clearSearch()">clear</igx-icon>
11+
}
12+
</igx-prefix>
13+
14+
<input #search1 id="search1" igxInput placeholder="Search" [(ngModel)]="searchText" (ngModelChange)="grid.findNext(searchText, false, false)"
15+
(keydown)="searchKeyDown($event)" />
16+
17+
@if (searchText.length > 0) {
18+
<igx-suffix>
19+
@if (grid.lastSearchInfo) {
20+
<div class="resultsText">
21+
@if (grid.lastSearchInfo.matchInfoCache.length > 0) {
22+
<span>
23+
{{ grid.lastSearchInfo.activeMatchIndex + 1 }} of {{ grid.lastSearchInfo.matchInfoCache.length }}
24+
results
25+
</span>
26+
}
27+
@if (grid.lastSearchInfo.matchInfoCache.length === 0) {
28+
<span>
29+
No results
30+
</span>
31+
}
32+
</div>
33+
}
34+
<div class="searchButtons">
35+
<button igxIconButton="flat" igxRipple (click)="grid.findPrev(searchText, false, false)">
36+
<igx-icon family="material">navigate_before</igx-icon>
37+
</button>
38+
<button igxIconButton="flat" igxRipple (click)="grid.findNext(searchText, false, false)">
39+
<igx-icon family="material">navigate_next</igx-icon>
40+
</button>
41+
</div>
42+
</igx-suffix>
43+
}
44+
</igx-input-group>
45+
</div>
46+
<igx-grid [data]="data" width="800px" height="550px" [moving]="true" #grid1
347
[cellMergeMode]="'always'" [rowSelection]="'single'">
448
<igx-column field="ProductID" header="Product ID" width="200px">
549
<ng-template igxCell let-cell="cell" let-val>

src/app/grid-cellMerging/grid-cellMerging.component.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ import {
1313
IgxGridToolbarHidingComponent,
1414
IgxGridToolbarPinningComponent,
1515
IgxHierarchicalGridComponent,
16+
IgxIconComponent,
17+
IgxInputDirective,
18+
IgxInputGroupComponent,
1619
IgxPaginatorComponent,
20+
IgxPrefixDirective,
1721
IgxRowIslandComponent,
22+
IgxSuffixDirective,
1823
IgxTreeGridComponent
1924
} from 'igniteui-angular';
2025
import { HIERARCHICAL_DATA } from '../shared/hierarchicalData';
@@ -43,7 +48,12 @@ import { ByLevelTreeGridMergeStrategy } from 'igniteui-angular';
4348
IgxGridToolbarExporterComponent,
4449
IgxHierarchicalGridComponent,
4550
IgxRowIslandComponent,
46-
IgxTreeGridComponent
51+
IgxTreeGridComponent,
52+
IgxInputGroupComponent,
53+
IgxPrefixDirective,
54+
IgxSuffixDirective,
55+
IgxIconComponent,
56+
IgxInputDirective
4757
]
4858
})
4959
export class GridCellMergingComponent {
@@ -52,6 +62,8 @@ export class GridCellMergingComponent {
5262
public treeGridMergeStrategy = new ByLevelTreeGridMergeStrategy();
5363
public alignBottom = { alignItems: "flex-end", paddingBottom: "12px"};
5464
public alignTop= { alignItems: "flex-start", paddingTop: "12px" };
65+
public searchText: string ='';
66+
@ViewChild('grid1', { static: true }) public grid: IgxGridComponent;
5567
public data = [{
5668
ProductID: 1,
5769
ProductName: 'Chai',
@@ -387,5 +399,19 @@ export class GridCellMergingComponent {
387399
OrderDate2: new Date(1991, 2, 12, 15, 40, 50).toISOString()
388400
}];
389401

402+
public searchKeyDown(ev) {
403+
if (ev.key === 'Enter' || ev.key === 'ArrowDown' || ev.key === 'ArrowRight') {
404+
ev.preventDefault();
405+
this.grid.findNext(this.searchText, true, false);
406+
} else if (ev.key === 'ArrowUp' || ev.key === 'ArrowLeft') {
407+
ev.preventDefault();
408+
this.grid.findPrev(this.searchText, true, false);
409+
}
410+
}
411+
412+
public clearSearch() {
413+
this.searchText = '';
414+
this.grid.clearSearch();
415+
}
390416
}
391417

0 commit comments

Comments
 (0)