Repository: h2oai/wave
File: py/examples/table_pagination_h2o3.py (Python)

Code before:
            logger.info(f"table sort: {q.events.h2o_table.sort}")
            q.client.sort = q.events.h2o_table.sort
            q.client.page_offset = 0

        if q.events.h2o_table.filter:
            logger.info(f"table filter: {q.events.h2o_table.filter}")
            q.client.filters = q.events.h2o_table.filter
            q.client.page_offset = 0

        if q.events.h2o_table.search is not None:
            logger.info(f"table search: {q.events.h2o_table.search}")
            q.client.search = q.events.h2o_table.search
            q.client.page_offset = 0

        if q.events.h2o_table.download:
            await download_h2o_table(q)

        if q.events.h2o_table.reset:
            logger.info("table reset")
            q.client.search = None
            q.client.sort = None
            q.client.filters = None
            q.client.page_offset = 0
            q.client.total_rows = len(q.app.h2o_df)

        # Update the rows on in our UI
        # TODO: if you change where your table is located, this needs updating
        q.page["table_card"].items[0].table.rows = get_table_rows(q)
        q.page["table_card"].items[0].table.pagination.total_rows = q.client.total_rows

    await q.page.save()


def get_table_rows(q: Q):
    logger.info(
        f"Creating new table for rows: {q.client.page_offset} to {q.client.page_offset + q.app.rows_per_page}"
    )

    working_frame = prepare_h2o_data(q)

    # Bring our limited UI rows locally to pandas to prepare for our ui.table
    local_df = working_frame[
        q.client.page_offset : q.client.page_offset + q.app.rows_per_page, :
    ].as_data_frame()
    q.client.total_rows = len(working_frame)

    table_rows = [
        ui.table_row(
            name=str(
                q.client.page_offset + i
            ),  # name is the index on the h2o dataframe for appropriate lookup

Review comment (suggestion):
```suggestion
        # Update the rows in our UI
```

Code after:
            logger.info(f"table sort: {q.events.h2o_table.sort}")
            q.client.sort = q.events.h2o_table.sort
            q.client.page_offset = 0

        if q.events.h2o_table.filter:
            logger.info(f"table filter: {q.events.h2o_table.filter}")
            q.client.filters = q.events.h2o_table.filter
            q.client.page_offset = 0

        if q.events.h2o_table.search is not None:
            logger.info(f"table search: {q.events.h2o_table.search}")
            q.client.search = q.events.h2o_table.search
            q.client.page_offset = 0

        if q.events.h2o_table.download:
            await download_h2o_table(q)

        if q.events.h2o_table.reset:
            logger.info("table reset")
            q.client.search = None
            q.client.sort = None
            q.client.filters = None
            q.client.page_offset = 0
            q.client.total_rows = len(q.app.h2o_df)

        # Update the rows in our UI
        # TODO: if you change where your table is located, this needs updating
        q.page["table_card"].items[0].table.rows = get_table_rows(q)
        q.page["table_card"].items[0].table.pagination.total_rows = q.client.total_rows

    await q.page.save()


def get_table_rows(q: Q):
    logger.info(
        f"Creating new table for rows: {q.client.page_offset} to {q.client.page_offset + q.app.rows_per_page}"
    )

    working_frame = prepare_h2o_data(q)

    # Bring our limited UI rows locally to pandas to prepare for our ui.table
    local_df = working_frame[
        q.client.page_offset : q.client.page_offset + q.app.rows_per_page, :
    ].as_data_frame()
    q.client.total_rows = len(working_frame)

    table_rows = [
        ui.table_row(
            name=str(
                q.client.page_offset + i
            ),  # name is the index on the h2o dataframe for appropriate lookup