Comments (7)
Thank you @ankurheble for providing the updated demo, this indeed is something we could fix internally.
I've raised a PR for the fix to this particular problem, you can test it in this live csb example too. Let me know if it looks good to you now.
For the broader problem, I agree the dx is not great and it should be improved, thank you @flaviendelangle for the suggestion, I remember we did discuss the problem during the implementation of header filters but settled on the same thing which was in normal filters back then.
I've created a separate issue to track and solve this problem.
from mui-x.
I had the same problem in my personal app
IMHO this is a bad practice:
const label =
op?.headerLabel ??
apiRef.current.getLocaleText(
`headerFilterOperator${capitalize(op.value)}` as 'headerFilterOperatorContains',
);
It crashes even though the headerLabel
is supposed to be optional.
Not sure how we could improve it (wrap in a try
to avoid crashing and render an empty label? check if the translation key exists before calling getLocaleText
? Create a getOptionalLocaleText
method?), but right now it's a bad DX.
To be clear, this code have been here for ages, it's not a new problem at all, it was already here when I was working on the grid.
from mui-x.
@ankurheble Just like you provide label
for regular filter in a custom GridFilterOperator
, you can add a headerLabel
for header filters.
Something like:
const quantityOnlyOperators: GridFilterOperator<any, number>[] = [
{
label: "Between",
headerLabel: "Between", // newly added property
...otherProperties,
},
];
I've tried to update it in your demo, here's the forked version: https://codesandbox.io/p/sandbox/async-snow-nqcjz3
Let me know if it solves your issue.
Thanks
from mui-x.
Similar issues:
from mui-x.
Thanks, this somehow didn't work in my local even though headerLabel was provided... but it might be something i'm doing wrong! I see the demo link you provided is working.. I'll try this again.. thanks @MBilalShafi
from mui-x.
@MBilalShafi I tried your solution but it appears to work only for 1 custom filter.. I tried to include the default numeric filters along with the custom one and it still fails with the same translation key error.
Code snippet changed for operator declaration as below:
const quantityOnlyOperators: GridFilterOperator<any, number>[] = [
...getGridNumericOperators(),
{
label: "Between",
value: "between",
headerLabel: "Between",
getApplyFilterFn: (filterItem) => {
if (!Array.isArray(filterItem.value) || filterItem.value.length !== 2) {
return null;
}
if (filterItem.value[0] == null || filterItem.value[1] == null) {
return null;
}
return (value) => {
return (
value !== null &&
filterItem.value[0] <= value &&
value <= filterItem.value[1]
);
};
},
InputComponent: InputNumberInterval,
},
];
Updated my codesandbox to reflect this https://codesandbox.io/p/sandbox/nostalgic-pascal-9twstk?file=%2Fsrc%2FDemo.tsx%3A91%2C1-114%2C3
from mui-x.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.
@ankurheble: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.
from mui-x.
Related Issues (20)
- [data grid] Save and restore filtermodels HOT 1
- [charts][core] Replace useIsomorphicLayoutEffect of @react-spring/web for Base UI's helper HOT 5
- [data grid] Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release HOT 3
- [data grid] Columns selection component losing anchorElement/scroll state HOT 5
- [data grid] Lazy loading details when using Master detail feature HOT 4
- [pickers] How to customize the `DatePicker` calendar header? HOT 2
- [data grid] License works locally but not on Vercel production HOT 3
- [data grid] Extra space on the bottom of grid when loading new records and scrolling back up HOT 1
- [data grid] filter and columns poppers incorrectly positioned when using a toolbar HOT 1
- [data grid] Bottom border doesn't reflect on pinned columns HOT 6
- [data grid] Deleting a row on cell Key down triggers an error HOT 2
- [pickers] add option to open calendar popover when text field is selected HOT 4
- [data grid] Is there a way to ignore the actions columns on paste in the data grid? HOT 2
- [charts] hovering over charts causes 'maximum update depth exceeded' error HOT 6
- [data grid] Is it possible to add reusable DataGrid GridToolbar components that make use of slots and slotProps? HOT 2
- [data grid] When wrapping custom renderHeader components in a Tooltip, it alway shows on hover, still appearing when there is no ellipsis HOT 3
- [TreeView] Can't type a space in an input rendered in the item HOT 5
- [data grid] Column flex width jumps after grid is displayed HOT 1
- [data grid] Problems with copy/paste and the autocomplete dropdown HOT 3
- [pickers] How to change mui toolbar date text colour and max width to 1000 HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mui-x.