-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Make filters work with custom input with 2 fields #817
Comments
Same here |
I'm surprised it even works the first time - the filter system wasn't designed to support combined filters. I consider it an enhancement request. |
@fzaninotto Yes, after looking at the filters code, I was surprised too. |
Hi. <PeriodInput
source="between"
fromLabel="from"
fromSource="between.gte"
toLabel="to"
toSource="between.lte"
label="period"
/> you can use more than one field. and this is the solution i've searching for. so the code remove the filter name as mentioned in source. return (
<span style={styles.row}>
<Field
name={`${this.props.source}.gte`} //<<<
label={this.props.fromLabel}
component={DateInput}
/>
<Field
name={`${this.props.source}.lte`}//<<<
label={this.props.toLabel}
component={DateInput}
/>
</span>
); |
Hi.
I'm new, and I have a few questions:
|
Thanks @wmwart , I extracted this to a reusable component: import React from "react";
const styles = {
row: {
display: "flex",
flexDirection: "row",
alignItems: "flex-start",
justifyContent: "space-between",
},
};
export class InputRow extends React.PureComponent {
render() {
const { children, ...rest } = this.props;
return (
<span style={styles.row}>
{React.Children.map(children, child => {
return React.cloneElement(child, rest);
})}
</span>
);
}
} and now you can just wrap any inputs with it: <InputRow>
<TextInput source="field1" />
<TextInput source="field2" />
</InputRow> |
Still seems this doesn't work to clear the combined input filter? Anyone found a solution to this yet? |
In case somebody is still stuck clearing custom or multiple filters: First, be careful with @waynebloss solution based on @wmwart's. It won't put labels on the filter dropdown because you are missing the <MultipleFilter source="nameOfTheFilter">
<Textinput source="nameOfTheFilter_lt" />
<Textinput source="nameOfTheFilter_gt" />
</MultipleFilter>
// ... In your component
const MultipleFilter = ({ children, source, ...rest }) => (
<span style={styles.row}>
{React.Children.map(children, (child) => {
return React.cloneElement(child, rest);
})}
</span>
); But RA does not know to clear those inputs, it will only clear the "aggregated source name" and let others as they are. One idea could be just implementing your backend to ignore filters when there's no aggregated filter present. If you send "nameOfTheFilter", that has inside "nameOfTheFilter_gt" and "nameOfTheFilter_lt" just don't filter by any of them unless "nameOfTheFilter" is present. The only "workaround" I found without backend code is implement everything as custom, from the input to the filters and filter consolidation system, and it's not worth it, you'd be better not using React Admin at all. |
This is now possible thanks to StackedFilters |
Hello,
I tried to create a "between" like filter with 2 DateInput :
The filter works, when I choose it from the filters list, the two fields display well, I can choose dates and filter as expected. But when I use the cross to clear the filter, it does disapear, but it's not cleared as wanted. Clicking again on the filter in the filters list, display the filter with the previsously chosen values.
Thanks for your help !
PS: you always need to set the source property for the input in filters if you want to avoid a hideFilter console error.
The text was updated successfully, but these errors were encountered: