Skip to content

Commit b5952a7

Browse files
authored
fix(filtering): add row data param to formatter (#10204)
1 parent 2709c3d commit b5952a7

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

projects/igniteui-angular/src/lib/data-operations/filtering-strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class FormattedValuesFilteringStrategy extends FilteringStrategy {
134134
let value = resolveNestedPath(rec, fieldName);
135135

136136
value = column.formatter && this.shouldApplyFormatter(fieldName) ?
137-
column.formatter(value) : value && (isDate || isTime) ? parseDate(value) : value;
137+
column.formatter(value, rec) : value && (isDate || isTime) ? parseDate(value) : value;
138138

139139
return value;
140140
}

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-advanced.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,40 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
18071807
expect(rows.length).toEqual(3, 'Wrong filtered rows count');
18081808
}));
18091809

1810+
it('Should filter by cells formatted data when using FormattedValuesFilteringStrategy with rowData', fakeAsync(() => {
1811+
const formattedStrategy = new FormattedValuesFilteringStrategy(['ProductName']);
1812+
grid.filterStrategy = formattedStrategy;
1813+
const anotherFieldFormatter = (value: any, rowData: any) => rowData.ID + ':' + value;
1814+
grid.columns[1].formatter = anotherFieldFormatter;
1815+
fix.detectChanges();
1816+
1817+
grid.openAdvancedFilteringDialog();
1818+
tick(200);
1819+
fix.detectChanges();
1820+
1821+
// Add root group.
1822+
GridFunctions.clickAdvancedFilteringInitialAddGroupButton(fix, 0);
1823+
tick(100);
1824+
fix.detectChanges();
1825+
1826+
// Add a new expression
1827+
selectColumnInEditModeExpression(fix, 1); // Select 'ProductName' column.
1828+
selectOperatorInEditModeExpression(fix, 0); // Select 'Contains' operator.
1829+
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
1830+
UIInteractions.clickAndSendInputElementValue(input, '1:', fix); // Type filter value.
1831+
1832+
// Commit the populated expression.
1833+
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
1834+
tick(100);
1835+
fix.detectChanges();
1836+
GridFunctions.clickAdvancedFilteringApplyButton(fix);
1837+
tick(100);
1838+
fix.detectChanges();
1839+
1840+
const rows = GridFunctions.getRows(fix);
1841+
expect(rows.length).toEqual(1, 'Wrong filtered rows count');
1842+
}));
1843+
18101844
describe('Context Menu - ', () => {
18111845
it('Should discard added group when clicking its operator line without having a single expression.', fakeAsync(() => {
18121846
// Open Advanced Filtering dialog.

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-ui.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,25 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
21792179
expect(rows.length).toEqual(2);
21802180
}));
21812181

2182+
it('Should filter by cells formatted data when using FormattedValuesFilteringStrategy with rowData', fakeAsync(() => {
2183+
const formattedStrategy = new FormattedValuesFilteringStrategy(['ProductName']);
2184+
grid.filterStrategy = formattedStrategy;
2185+
const anotherFieldFormatter = (value: any, rowData: any) => rowData.ID + ':' + value;
2186+
grid.columns[1].formatter = anotherFieldFormatter;
2187+
fix.detectChanges();
2188+
2189+
GridFunctions.clickFilterCellChipUI(fix, 'ProductName');
2190+
fix.detectChanges();
2191+
2192+
GridFunctions.typeValueInFilterRowInput('1:', fix);
2193+
tick(DEBOUNCETIME);
2194+
GridFunctions.closeFilterRow(fix);
2195+
fix.detectChanges();
2196+
2197+
const rows = GridFunctions.getRows(fix);
2198+
expect(rows.length).toEqual(1);
2199+
}));
2200+
21822201
it('Should remove pending chip via its close button #9333', fakeAsync(() => {
21832202
GridFunctions.clickFilterCellChipUI(fix, 'Downloads');
21842203
fix.detectChanges();

0 commit comments

Comments
 (0)