-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Fix cell value type in quick filtering v7 #10884
Changes from 3 commits
456018f
c89d525
a768f31
f41c87e
decaba4
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ import { | |
GridQuickFilterValueResult, | ||
} from './gridFilterState'; | ||
import { buildWarning } from '../../../utils/warning'; | ||
import { getPublicApiRef } from '../../../utils/getPublicApiRef'; | ||
import { | ||
gridColumnFieldsSelector, | ||
gridColumnLookupSelector, | ||
|
@@ -152,7 +153,7 @@ export const mergeStateWithFilterModel = | |
filterModel: sanitizeFilterModel(filterModel, disableMultipleColumnsFiltering, apiRef), | ||
}); | ||
|
||
const removeDiacritics = (value: unknown) => { | ||
export const removeDiacritics = (value: unknown) => { | ||
if (typeof value === 'string') { | ||
return value.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); | ||
} | ||
|
@@ -220,7 +221,7 @@ const getFilterCallbackFromItem = ( | |
if (ignoreDiacritics) { | ||
value = removeDiacritics(value); | ||
} | ||
return applyFilterOnRow(value, row, column, apiRef); | ||
return applyFilterOnRow(value, row, column, getPublicApiRef(apiRef)); | ||
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. We were passing private apiRef here 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. Oops, nice catch 👍 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. Can we create the API ref outside this function? I think this one is inside the filter loop, so we're doing 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. Same comment applies below, line 420. 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. Thanks for catching it, updated it! |
||
}, | ||
}; | ||
} | ||
|
@@ -371,7 +372,7 @@ const buildAggregatedQuickFilterApplier = ( | |
const value = ignoreDiacritics ? removeDiacritics(quickFilterValue) : quickFilterValue; | ||
return { | ||
v7: true, | ||
fn: getApplyQuickFilterFnV7(value, column, apiRef), | ||
fn: getApplyQuickFilterFnV7(value, column, getPublicApiRef(apiRef)), | ||
}; | ||
}), | ||
}); | ||
|
@@ -382,7 +383,7 @@ const buildAggregatedQuickFilterApplier = ( | |
const value = ignoreDiacritics ? removeDiacritics(quickFilterValue) : quickFilterValue; | ||
return { | ||
v7: false, | ||
fn: getApplyQuickFilterFn(value, column, apiRef), | ||
fn: getApplyQuickFilterFn(value, column, getPublicApiRef(apiRef)), | ||
}; | ||
}), | ||
}); | ||
|
@@ -406,7 +407,7 @@ const buildAggregatedQuickFilterApplier = ( | |
} | ||
|
||
const applier = appliers[v]; | ||
let value = apiRef.current.getRowFormattedValue(row, column); | ||
let value = apiRef.current.getRowValue(row, column); | ||
|
||
if (applier.fn === null) { | ||
continue; | ||
|
@@ -416,7 +417,7 @@ const buildAggregatedQuickFilterApplier = ( | |
if (ignoreDiacritics) { | ||
value = removeDiacritics(value); | ||
} | ||
const isMatching = applier.fn(value, row, column, apiRef); | ||
const isMatching = applier.fn(value, row, column, getPublicApiRef(apiRef)); | ||
if (isMatching) { | ||
result[filterValue] = true; | ||
continue outer; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { GridPrivateApiCommunity } from '../models/api/gridApiCommunity'; | ||
|
||
export function getPublicApiRef<PrivateApi extends GridPrivateApiCommunity>( | ||
apiRef: React.MutableRefObject<PrivateApi>, | ||
) { | ||
return { current: apiRef.current.getPublicApi() } as React.MutableRefObject< | ||
ReturnType<PrivateApi['getPublicApi']> | ||
>; | ||
} |
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.
This is a disadvantage compared to v6 filtering, where it was possible to overwrite the
cellParams.formattedValue
.