Skip to content

ui.table export data #366

Closed Answered by Diegiwg
bderkk asked this question in Q&A
Feb 12, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Well, I don't know if that's what you wanted, but I managed to extract the information, such as a list of data present in the table.

Below is an example code, and output value when ordering to extract the information.

from nicegui import ui

table = ui.table


async def export_data():
    js = f"""
    const table = getElement({table.id});
    const raw = table.gridOptions.api.getDataAsCsv();
    const data = [];
    raw.split('\\r\\n').forEach(el => data.push(el.replaceAll('"',"").split(',')))
    return data;
    """

    data: list[str] = await ui.run_javascript(js)

    print(data)
    for el in data:
        print(f"{el[0]} | {el[1]}")


@ui.page("/")
async def page():
    global table

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

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

This discussion was converted from issue #365 on February 12, 2023 09:56.