-
Notifications
You must be signed in to change notification settings - Fork 41
enable filter handlers #436
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
Merged
Merged
+106
−3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
Author
|
Here's a sample app: from dash import Dash, html
import dash_ag_grid as dag
import pandas as pd
app = Dash(__name__)
print(dag.__version__)
df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
)
rowData = df.to_dict('records')
columnDefs = [
{ 'field': 'age', 'filter': 'agNumberColumnFilter' },
{ 'field': 'country', 'minWidth': 150 },
{ 'field': 'year', 'filter': {'component': 'YearFilter35', 'doesFilterPass': {'function': 'doesFilterPass'}}},
{
'field': 'date',
'minWidth': 130,
'filter': 'agDateColumnFilter',
'filterParams': {
'comparator': {'function':'dateComparator'},
},
},
{ 'field': 'sport' },
{ 'field': 'gold', 'filter': 'agNumberColumnFilter' },
{ 'field': 'silver', 'filter': 'agNumberColumnFilter' },
{ 'field': 'bronze', 'filter': 'agNumberColumnFilter' },
{ 'field': 'total', 'filter': 'agNumberColumnFilter' },
]
defaultColDef = {
'editable': True,
'sortable': True,
'flex': 1,
'minWidth': 100,
'filter': True,
'resizable': True,
}
app.layout = html.Div(
[
html.H3("See the custom filter component in the Year column v35"),
dag.AgGrid(
id="grid",
columnDefs=columnDefs,
rowData=rowData,
defaultColDef=defaultColDef,
# Needs to be set in dash-ag-grid>=34.0 with filter logic sep from component
dashGridOptions={"enableFilterHandlers": True}
),
]
)
if __name__ == "__main__":
app.run(host="127.0.0.1", debug=True)var dagfuncs = window.dashAgGridFunctions = window.dashAgGridFunctions || {};
const {useImperativeHandle, useState, useEffect} = React;
// for v35 filter logic separate
dagfuncs.doesFilterPass = (params) => {
return params.data.year >= 2010;
}
var dagcomponentfuncs = (window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {});
dagcomponentfuncs.YearFilter35 = ((props) => {
const [year, setYear] = useState('All');
useEffect(() => {
props.onModelChange(year === "All" ? null : year)
}, [year]);
setProps = ({value}) => {
if (value) {
setYear(value)
}
}
return React.createElement(
window.dash_core_components.RadioItems,
{
options: [
{'label': 'All', 'value': 'All'},
{'label': 'Since 2010', 'value': '2010'},
],
value: year,
setProps
}
)
};
|
Collaborator
|
Please add a test and a changelog entry |
BSd3v
approved these changes
Feb 2, 2026
Collaborator
BSd3v
left a comment
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.
💃
Collaborator
Author
|
@BSd3v This change needs to go in both v34 and v35. What's the best way to do that? |
Collaborator
|
Merge this PR in, and then take these changes into v34 as well. You should be able to cherry pick the changes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add more props to propCategories.js to enable function:
in
filteraddeddoesFilterPassandhandlerThis makes it possible to make custom filter components as recommended in V34
https://www.ag-grid.com/react-data-grid/upgrading-to-ag-grid-34/#filters