Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing value to table with 'select' event leads to trigger-loop #2069

Closed
aranvir opened this issue Jul 10, 2023 · 1 comment · Fixed by #2082
Closed

Passing value to table with 'select' event leads to trigger-loop #2069

aranvir opened this issue Jul 10, 2023 · 1 comment · Fixed by #2082
Assignees
Labels
bug Bug in code ui Related to UI

Comments

@aranvir
Copy link
Contributor

aranvir commented Jul 10, 2023

Wave SDK Version, OS

h2o-wave 0.26.1, Windows 10

Actual behavior

If a table has single=True and events=['select'], passing the selected value to the value argument (e.g., value=q.args.table[0]) causes the page to enter a loop of infinite refresh.

  • The user selects a row
  • The page refreshes and passes the selection to the table
  • This triggers the select event and refreshes the page
  • Value is passed to table........

Expected behavior

Passing the current row value only fills the checkbox instead of triggering the select event (e.g., same behaviour as when there is no event assigned). The event should be triggered on mouse-click, not on having a default/past value passed.

My use case is: A table provides an overview of data. Clicking a row adds a new tile showing the complete data in case the user wants to see more details. For extra clarity, I'd like the table row to stay selected, but of course it works just as fine when the row is not selected (ergo, I just skip passing anything to value). I still thought I raised this issue in case this is indeed NOT the behaviour you wanted for the table.

Steps To Reproduce

  1. Run code below
  2. Select a row
  3. Witness infinite refreshs
from h2o_wave import main, app, Q, ui, on, data


async def table_page(q: Q):
    items = [ui.table(
            name='table',
            columns=[ui.table_column(name='text', label='Table select event')],
            rows=[
                ui.table_row(name='row1', cells=['Row 1']),
                ui.table_row(name='row2', cells=['Row 2']),
                ui.table_row(name='row3', cells=['Row 3'])
            ],
            single=True,
            events=['select'],
            value=q.args.table[0] if q.args.table else None
        )]

    if q.args.table:
        # Do something with the selected row, e.g., show more details 
        items.append(ui.text_xl(f"{q.args.table[0]} selected"))

    q.page['example'] = ui.form_card(box='1 1 3 4', items=items)


@app('/')
async def serve(q: Q):
    await table_page(q)
    await q.page.save()
@aranvir aranvir added the bug Bug in code label Jul 10, 2023
@mturoci
Copy link
Collaborator

mturoci commented Jul 12, 2023

Thanks for reporting @aranvir!

@mturoci mturoci added the ui Related to UI label Jul 12, 2023
marek-mihok added a commit that referenced this issue Jul 19, 2023
mturoci pushed a commit that referenced this issue Aug 17, 2023
mturoci pushed a commit that referenced this issue Aug 17, 2023
mturoci added a commit that referenced this issue Aug 17, 2023
… (#2082)

Co-authored-by: Martin Turoci <martin.turoci@h2o.ai>
marek-mihok added a commit that referenced this issue Jan 15, 2024
… (#2082)

Co-authored-by: Martin Turoci <martin.turoci@h2o.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in code ui Related to UI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants