Skip to content

Commit c87759d

Browse files
authored
Merge pull request #413 from andre996/multifilterFunction
Adding filters to COLUMN_ARRAY_NESTED_FUNCTIONS
2 parents d513f3e + c3d482a commit c87759d

File tree

4 files changed

+137
-1
lines changed

4 files changed

+137
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source D
99
- [#408](https://github.com/plotly/dash-ag-grid/pull/408) fixed issue where the `columnState` would conflict with `columnDefs` updates
1010
- fixes [#416] (https://github.com/plotly/dash-ag-grid/issues/416)
1111
- fixes [#407](https://github.com/plotly/dash-ag-grid/issues/407)
12+
- [#412](https://github.com/plotly/dash-ag-grid/issues/412) fix "Multi-Column Filter not properly recognized in filterParams"
1213

1314
## [33.3.2rc2] - 2025-09-17
1415

src/lib/utils/propCategories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ export const COLUMN_NESTED_OR_OBJ_OF_FUNCTIONS = {
301301
export const COLUMN_ARRAY_NESTED_FUNCTIONS = {
302302
children: 1,
303303
filterOptions: 1,
304+
filters: 1,
304305
};
305306

306307
/**

tests/assets/dashAgGridFunctions.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,41 @@ dagfuncs.startWith = ([filterValues], cellValue) => {
396396
const name = cellValue ? cellValue.split(" ")[1] : ""
397397
return name && name.toLowerCase().indexOf(filterValues.toLowerCase()) === 0
398398
}
399+
400+
dagfuncs.dateFilterComparator = (filterLocalDateAtMidnight, cellValue) => {
401+
const dateAsString = cellValue;
402+
403+
if (dateAsString == null) {
404+
// Return -1 to show nulls "before" any date
405+
return -1;
406+
}
407+
408+
// The data from this CSV is in dd/mm/yyyy format
409+
const dateParts = dateAsString.split("/");
410+
if (dateParts.length !== 3) {
411+
// Handle invalid format
412+
return 0;
413+
}
414+
415+
const day = Number(dateParts[0]);
416+
const month = Number(dateParts[1]) - 1; // JS months are 0-indexed
417+
const year = Number(dateParts[2]);
418+
const cellDate = new Date(year, month, day);
419+
420+
// Check for invalid date (e.g., from "NaN")
421+
if (isNaN(cellDate.getTime())) {
422+
return 0;
423+
}
424+
425+
// Now that both parameters are Date objects, we can compare
426+
if (cellDate < filterLocalDateAtMidnight) {
427+
return -1;
428+
} else if (cellDate > filterLocalDateAtMidnight) {
429+
return 1;
430+
}
431+
return 0;
432+
};
433+
399434
// END test_custom_filter.py
400435

401436
// FOR test_quick_filter.py
@@ -502,4 +537,5 @@ dagfuncs.TestEvent = (params, setEventData) => {
502537

503538
dagfuncs.testToyota = (params) => {
504539
return params.data.make == 'Toyota' ? {'color': 'blue'} : {}
505-
}
540+
}
541+

tests/test_custom_filter.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,101 @@ def test_fi005_custom_filter(dash_duo):
236236
# Test numberParser and numberFormatter
237237
grid.set_filter(0, "$100,5")
238238
grid.wait_for_cell_text(0, 0, "$200,00")
239+
240+
def test_fi006_custom_filter(dash_duo):
241+
app = Dash(__name__)
242+
243+
df = pd.read_csv(
244+
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
245+
)
246+
247+
columnDefs = [
248+
{"field": "athlete",
249+
"filter": "agMultiColumnFilter",
250+
"filterParams": {
251+
"filters": [
252+
{"filter": "agTextColumnFilter"},
253+
{"filter": "agSetColumnFilter"} # Example with Set Filter
254+
]
255+
}},
256+
{"field": "country"},
257+
{
258+
"field": "date",
259+
"filter": "agMultiColumnFilter",
260+
"filterParams": {
261+
"filters": [
262+
{
263+
"filter": "agSetColumnFilter",
264+
'filterParams': {'excelMode': 'windows', 'buttons': ['apply', 'reset'],
265+
}
266+
},
267+
{
268+
"filter": "agDateColumnFilter",
269+
'filterParams': {
270+
'excelMode': 'windows',
271+
'buttons': ['apply', 'reset'],
272+
'comparator': {'function': 'dateFilterComparator'},
273+
}
274+
},
275+
],
276+
277+
},
278+
},
279+
]
280+
281+
282+
app.layout = html.Div(
283+
[
284+
dag.AgGrid(
285+
id="date-filter-example",
286+
enableEnterpriseModules=True,
287+
columnDefs=columnDefs,
288+
rowData=df.to_dict("records"),
289+
defaultColDef={"flex": 1, "minWidth": 150, "floatingFilter": True},
290+
dashGridOptions={"animateRows": False}
291+
),
292+
],
293+
)
294+
295+
dash_duo.start_server(app)
296+
297+
grid = utils.Grid(dash_duo, "date-filter-example")
298+
299+
grid.wait_for_cell_text(0, 0, "Michael Phelps")
300+
301+
# Test Set Filter - click filter button on date column
302+
dash_duo.find_element('.ag-floating-filter[aria-colindex="3"] button').click()
303+
304+
# Uncheck "Select All"
305+
dash_duo.find_element('.ag-set-filter-list .ag-set-filter-item .ag-checkbox-input').click()
306+
307+
# Select "24/08/2008"
308+
dash_duo.wait_for_element('.ag-set-filter-list .ag-virtual-list-item', timeout=10)
309+
set_filter_items = dash_duo.find_elements('.ag-set-filter-list .ag-virtual-list-item')
310+
checkboxes = dash_duo.find_elements('.ag-set-filter-list .ag-virtual-list-item .ag-checkbox-input')
311+
312+
for i, item in enumerate(set_filter_items):
313+
if "24/08/2008" in item.text:
314+
checkboxes[i].click()
315+
break
316+
317+
# Apply
318+
dash_duo.find_element('button[data-ref="applyFilterButton"]').click()
319+
grid.wait_for_cell_text(0, 2, "24/08/2008")
320+
321+
# Reset
322+
dash_duo.find_element('.ag-floating-filter[aria-colindex="3"] button').click()
323+
dash_duo.find_element('button[data-ref="resetFilterButton"]').click()
324+
325+
# Test Date Filter - click filter button again
326+
dash_duo.find_element('.ag-floating-filter[aria-colindex="3"] button').click()
327+
328+
# Type date
329+
date_input = dash_duo.find_element('.ag-filter-wrapper .ag-date-filter input[class="ag-input-field-input ag-text-field-input"]')
330+
date_input.click()
331+
date_input.send_keys("24-08-2008")
332+
333+
# Apply
334+
apply_buttons = dash_duo.find_elements('button[data-ref="applyFilterButton"]')
335+
apply_buttons[1].click()
336+
grid.wait_for_cell_text(0, 2, "24/08/2008")

0 commit comments

Comments
 (0)