How to get filtered rows from AG Grid table? #4705
Closed
Anindya088
started this conversation in
Ideas / Feature Requests
Replies: 1 comment 3 replies
-
Hi @Anindya088, Unfortunately I don't see an easier way than running custom JavaScript including @ui.page('/')
def page():
grid = ui.aggrid({
'columnDefs': [
{'headerName': 'Name', 'field': 'name', 'filter': 'agTextColumnFilter', 'floatingFilter': True},
{'headerName': 'Age', 'field': 'age', 'filter': 'agNumberColumnFilter', 'floatingFilter': True},
],
'rowData': [
{'name': 'Alice', 'age': 18},
{'name': 'Bob', 'age': 21},
{'name': 'Carol', 'age': 42},
],
})
async def get_filtered_rows():
rows = await ui.run_javascript(f'''
const grid = getElement({grid.id});
const rows = [];
grid.api.forEachNodeAfterFilter(node => rows.push(node.data));
return rows;
''')
print(rows)
ui.button('Get filtered rows', on_click=get_filtered_rows) If you think this is a common use case, we could add a |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Example Code
Description
Hi All,
I am struggling to get the filtered rows at backend when using AG Grid tables. Is there any easy way to do this?
So far, what I saw/understood is:
Option 1: use the
await grid.run_grid_method('getFilterModel')
to get the filter dictionary and apply those filters manually on your own dataframeOption 2: I found some js code on AG Grid website about row iteration, but don't know how to use it in NiceGUI context, so what I found is this:
Please let me know if there is an easy way to achieve this. Thanks a lot for the help.
Regards,
Anindya
NiceGUI Version
2.14.1
Python Version
3.13.0
Browser
Chrome
Operating System
Windows
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions