Filtering table by selected rows

Hi everyone.

I’m trying to filter my Ag Grid table by using a toggle (Switch from Dash Mantine Components).

dmc.Switch(
                                        id=f"{prefix}__feature_selection_table_switch",
                                        label="Show Only Selected Rows",
                                        checked=False,
                                        mb=20,
                                        display="none",
                                    )

I want to filter my table so only rows that I selected are shown when I click on this toggle, but I can’t find reference for how to check if a row is selected or not.

This is what I have now in my callback:

@callback(
        Output(f"{prefix}__feature_selection_table", "dashGridOptions", allow_duplicate=True),
        Input(f"{prefix}__feature_selection_table_switch", "checked"),
        State(f"{prefix}__feature_selection_table", "dashGridOptions"),
        prevent_initial_call=True,
    )
    def filter_only_selected_rows(filter_checked: bool, options):
        grid_options = options
        grid_options["isExternalFilterPresent"] = {"function": "true" if filter_checked else "false"}
        grid_options["doesExternalFilterPass"] = {"function": "node.selected"}
        return grid_options

This node.selected condition is not working, and this needs to be changed for this to work, but I don’t know what to.

I’m using Dash 2.17.0 and AG Grid 31.2.0

Solved it using params.selected

1 Like

Hello,
To filter your Ag Grid table to show only selected rows when toggling a switch from Dash Mantine Components, adjust the doesExternalFilterPass function in your callback. Replace node.selected with a custom function that checks if each row is selected. Here’s a modified version of your callback with the necessary changes applied. This should correctly filter the table to display only selected rows when the switch is toggled.