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
List of filtered values should show the formatted numeric value not the source data #10756
Conversation
- Implement a new `getDisplayValuesAtCol` method - Make the filters' multi selection module utilize the newly created method - Set the new `displayValue` prop in the numeric renderer
- Resolve issues with the `displayValue`s being out of sync with the filtered-out data - Make the filter by value component use the source data for the comparing and filtering data, and the `displayValue` properties just in the UI
- Remove async logic from a test
Launch the local version of documentation by running: npm run docs:review 8f6a5f51261db15b47798bdc4b9b55224139948a |
…hod in the multiple selection component logic.
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.
I'm not convinced about that displayValue
option. I know that the purpose of this task is to add support for modifying filter values only for numeric values, but with this shape, it isn't very clear.
The question that comes to my mind or limitation that I found:
- The value can not be changed in the
cells
function. ThedisplayValue
property is always overwritten in the numeric renderer; - When the
displayValue
property does not exist, the Filters plugin generates one by calling the numeric renderer by itself. So what is this option for? Kind of read-only and for numeric columns only? - Maybe a better idea would be creating renderers for Filters. The same goes for cells. For example,
filtersRenderer
option, or so?
handsontable/src/renderers/numericRenderer/__tests__/numericRenderer.spec.js
Outdated
Show resolved
Hide resolved
I went through several approaches to this task, but I'll take any suggestions. As for the questions:
Yes. The spec requires the multi-selection component in the Filters dropdown to display the same value that's being rendered in the cells. As we cannot know what the renderer with generate, there's no way to assign this value before it's triggered.
I had to add this logic because the Filters dropdown display all unique values in the table, and the renderers are run just for the visible part of the dataset. Without this logic, some of the values were being displayed in their "source" form, and some in the "rendered" form.
We can do that, but according the the spec, in this case the |
Maybe I'd suggest adding a new hook for the MultipleSelect component of the Filters plugin. Let's name it Now, depending on the feature needs you can pass as many arguments as you wish. Usage example: modifyFiltersMultipleSelectValue(sourceValue, cellType, cellProperties) => {
let newValue = sourceValue;
if (cellType === 'numeric') {
if (isNumeric(newValue)) { // HERE I'd copy the logic from the renderer, or I can suggest moving it to a separate helper
const numericFormat = cellProperties.numericFormat;
const cellCulture = numericFormat && numericFormat.culture || '-';
const cellFormatPattern = numericFormat && numericFormat.pattern;
const className = cellProperties.className || '';
const classArr = className.length ? className.split(' ') : [];
if (typeof cellCulture !== 'undefined' && !numbro.languages()[cellCulture]) {
const shortTag = cellCulture.replace('-', '');
const langData = numbro.allLanguages ? numbro.allLanguages[cellCulture] : numbro[shortTag];
if (langData) {
numbro.registerLanguage(langData);
}
}
numbro.setLanguage(cellCulture);
newValue = numbro(newValue).format(cellFormatPattern || '0');
}
}
// PLACE FOR OTHER CELL TYPES
return newValue;
} |
- Add the `modifyFiltersMultipleSelectValue` plugin hook - Split the `numericRenderer` logic into two methods to use the value-generating one in the Filters plugin
Co-authored-by: Krzysztof Budnik <571316+budnix@users.noreply.github.com>
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.
It looks good. I left one comment with suggestions to be considered. And I wonder, would it be possible to pass a complete cellMeta object as a second argument? It would be better for the user not to have to figure out a new data structure. They already know/use cellMeta objects in other hooks or methods.
Ah, and I almost forgot. Can you add a TypeScript definition for |
Context
This PR:
modifyFiltersMultiSelectValue
hookmodifyFiltersMultiSelectValue
to display the rendered values for thenumeric
-typed cellsHow has this been tested?
Added new test cases.
Types of changes
Related issue(s):
Affected project(s):
handsontable
@handsontable/angular
@handsontable/react
@handsontable/vue
@handsontable/vue3
Checklist: