Q: Is it possible to customize the built in columns like the createTextColumn function? #77
-
Hello there, Amazing tool for online excels with great features. I would like to ask if it is possible to use the built-in columns and customize them like the createTextColumn? For example, I would like to limit the user to add values in a row from 1 - 1000. Is such a scenario possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The export const createIntColumn = ({ min, max }: { min: number, max: number}) => createTextColumn<number | null>({
alignRight: true,
formatBlurredInput: (value) =>
typeof value === 'number' ? new Intl.NumberFormat().format(value) : '',
parseUserInput: (value) => {
const number = parseFloat(value)
return !isNaN(number) ? Math.max(min, Math.min(max, Math.round(number))) : null
},
parsePastedValue: (value) => {
const number = parseFloat(value)
return !isNaN(number) ? Math.max(min, Math.min(max, Math.round(number))) : null
},
}) Built-in columns are not really meant to be exhaustive or offer many features (eg. select, tags, min-max...), they are just there to get you started. In a real-world use case you will end up implementing your own columns. This choice was made to keep the size of this package small and to prevent feature-creeping (there is always gonna be someone asking for a new column). The scope of this package is to allow anyone to implement anything. This means people can start creating dedicated package for specific columns. Hope that helps! |
Beta Was this translation helpful? Give feedback.
The
intColumn
is a few lines of codes only and actually usescreateTextColumn
(see code).You can simply copy-paste this in your code and change it as you see fit: