Skip to content

How to Modify the Search Bar (ui.input) Behavior in Table #3833

Closed Answered by python-and-novella
happybeginning1 asked this question in Q&A
Discussion options

You must be logged in to vote

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()

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@happybeginning1
Comment options

Answer selected by happybeginning1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants