How to Modify the Search Bar (ui.input) Behavior in Table #3833
-
QuestionHi, The following NiceGUI code works well for filtering the table. I have a few questions about refining the search functionality. from nicegui import ui
columns = [
{'name': 'name', 'label': 'Name', 'field': 'name', 'required': True, 'align': 'left'},
{'name': 'age', 'label': 'Age', 'field': 'age', 'sortable': True},
]
rows = [
{'name': 'Alice', 'age': 18},
{'name': 'Bob', 'age': 21},
{'name': 'Carol'},
]
table = ui.table(columns=columns, rows=rows, row_key='name')
ui.input().bind_value_to(table, 'filter')
ui.run()
Thank you very much for your help! |
Beta Was this translation helpful? Give feedback.
Answered by
python-and-novella
Oct 5, 2024
Replies: 1 comment 1 reply
-
For 1 and 2, you can hook keypress.enter and value_change events: from nicegui import ui
columns = [
{'name': 'name', 'label': 'Name', 'field': 'name', 'required': True, 'align': 'left'},
{'name': 'age', 'label': 'Age', 'field': 'age', 'sortable': True},
]
rows = [
{'name': 'Alice', 'age': 18},
{'name': 'Bob', 'age': 21},
{'name': 'Carol'},
]
table = ui.table(columns=columns, rows=rows, row_key='name')
inp = ui.input()
inp.on('keypress.enter',lambda e:table.set_filter(e.sender.value))
inp.on_value_change(lambda e: table.set_filter(None) if len(e.sender.value)==0 else None)
ui.run() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
happybeginning1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For 1 and 2, you can hook keypress.enter and value_change events: