### Install nicegui-tabulator Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Install the package using pip. ```bash pip install nicegui-tabulator ``` -------------------------------- ### Basic Table Usage Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Demonstrates creating a table with custom data and columns, including event handling for row clicks. ```python from nicegui_tabulator import tabulator from nicegui import ui tabledata = [ {"id": 1, "name": "Oli Bob", "age": "12", "col": "red", "dob": ""}, {"id": 2, "name": "Mary May", "age": "1", "col": "blue", "dob": "14/05/1982"}, { "id": 3, "name": "Christine Lobowski", "age": "42", "col": "green", "dob": "22/05/1982", }, { "id": 4, "name": "Brendon Philips", "age": "125", "col": "orange", "dob": "01/08/1980", }, { "id": 5, "name": "Margret Marmajuke", "age": "16", "col": "yellow", "dob": "31/01/1999", }, ] table_config = { "height": 205, "data": tabledata, "columns": [ {"title": "Name", "field": "name", "width": 150, "headerFilter": "input"}, {"title": "Age", "field": "age", "hozAlign": "left", "formatter": "progress"}, {"title": "Favourite Color", "field": "col"}, { "title": "Date Of Birth", "field": "dob", "sorter": "date", "hozAlign": "center", }, ], } table = tabulator(table_config).on_event("rowClick", lambda e: ui.notify(e)) def on_sort(): table.run_table_method( "setSort", [ {"column": "name", "dir": "desc"}, {"column": "age", "dir": "asc"}, ], ) u.button("sort", on_click=on_sort) ``` -------------------------------- ### Tabulator with Date Formatting and Sorting in NiceGUI Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Use this snippet to create a Tabulator table in NiceGUI with date formatting and sorting enabled. Ensure Luxon is imported for date/time functionalities. The table is configured with columns for 'Name' and 'Date Of Birth', where 'dob' is formatted and sorted as a date. ```python from nicegui import ui from nicegui.elements.tabulator import tabulator, import_luxon import_luxon(shared=True) # (app-wide) tabledata = [ {"id": 1, "name": "Oli Bob", "dob": "1982-05-14"}, {"id": 2, "name": "Mary May", "dob": "1999-01-31"}, ] table_config = { "layout": "fitColumns", "data": tabledata, "columns": [ {"title": "Name", "field": "name"}, { "title": "Date Of Birth", "field": "dob", "formatter": "datetime", "formatterParams": {"inputFormat": "iso", "outputFormat": "dd/MM/yyyy"}, "sorter": "date", "sorterParams": {"format": "iso"}, }, ], } tabulator(table_config) ui.run() ``` -------------------------------- ### Enable Luxon for Date/Time Features Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Tabulator's date and time functionalities require Luxon. Import it explicitly to enable these features. ```python from nicegui import ui from nicegui_tabulator import tabulator, import_luxon ``` -------------------------------- ### import_luxon Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Explicitly enables Luxon for Tabulator's date/time features, such as formatting and sorting. ```APIDOC ## import_luxon ### Description Explicitly enables Luxon for Tabulator's date/time features, such as formatting and sorting. ### Method POST ### Endpoint /import_luxon ### Parameters None ### Request Example ```python from nicegui_tabulator import import_luxon import_luxon() ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful import of Luxon. ``` -------------------------------- ### tabulator Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Creates a Tabulator table instance with the specified configuration. It can be used to display data and interact with the Tabulator library's features. Event listeners can be attached using the .on_event() method. ```APIDOC ## tabulator ### Description Creates a Tabulator table instance with the specified configuration. It can be used to display data and interact with the Tabulator library's features. Event listeners can be attached using the .on_event() method. ### Method POST ### Endpoint /tabulator ### Parameters #### Request Body - **table_config** (dict) - Required - Configuration object for the Tabulator table, including data, columns, and other settings. ### Request Example ```python tabledata = [ {"id": 1, "name": "Oli Bob", "age": "12", "col": "red", "dob": ""}, {"id": 2, "name": "Mary May", "age": "1", "col": "blue", "dob": "14/05/1982"}, ] table_config = { "height": 205, "data": tabledata, "columns": [ {"title": "Name", "field": "name", "width": 150, "headerFilter": "input"}, {"title": "Age", "field": "age", "hozAlign": "left", "formatter": "progress"}, ] } table = tabulator(table_config).on_event("rowClick", lambda e: ui.notify(e)) ``` ### Response #### Success Response (200) - **tabulator_instance** (object) - The created Tabulator table instance. ``` -------------------------------- ### use_theme Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Applies a predefined theme (e.g., 'bootstrap4', 'materialize') to the Tabulator tables. The theme can be applied globally or per client/page. ```APIDOC ## use_theme ### Description Applies a predefined theme (e.g., 'bootstrap4', 'materialize') to the Tabulator tables. The theme can be applied globally or per client/page. ### Method POST ### Endpoint /use_theme ### Parameters #### Request Body - **theme_name** (string) - Required - The name of the theme to apply (e.g., 'bootstrap4'). - **shared** (boolean) - Optional - If true, applies the theme to all clients. Defaults to true. ### Request Example ```python from nicegui_tabulator import use_theme # Use the theme for all clients use_theme('bootstrap4') # Use the theme only for the current client use_theme('bootstrap4', shared=False) ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful application of the theme. ``` -------------------------------- ### Apply Tabulator Themes Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Globally or locally apply themes like 'bootstrap4' to Tabulator tables. The `shared=False` option limits the theme to the current client. ```python from nicegui_tabulator import tabulator, use_theme # use the theme for all clients use_theme('bootstrap4') # use the theme only for the current client use_theme('bootstrap4', shared=False) @ui.page('/') def my_page(): # use the theme only for this page use_theme('bootstrap4') ``` -------------------------------- ### Cell Slot for Custom Cell Rendering Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Integrate NiceGUI components into table cells for interactive content. Use `add_cell_slot` to define custom rendering for specific columns. ```python from nicegui import ui from nicegui_tabulator import tabulator, CellSlotProps tabledata = [ {"id": 1, "name": "bar", "age": "12"}, {"id": 2, "name": "foo", "age": "1"}, ] table_config = { "data": tabledata, "columns": [ {"title": "Name", "field": "name"}, {"title": "Age", "field": "age"}, ], "printConfig": { "formatCells": False, }, } table = tabulator(table_config) @table.add_cell_slot("name") def _(props: CellSlotProps): # This function is called when rendering the cell of the table, and it receives the properties of the cell, # including the value of the cell, row index, column name, etc. # props.update_value(new_value) can update the value of the cell (updates server-side only, the client needs to manually refresh `sync_data_to_client`). ui.input(value=props.value, on_change=lambda e: props.update_value(e.value)) @table.add_cell_slot("age") def _(props: CellSlotProps): ui.number(value=props.value, min=0, max=100,on_change=lambda e: props.update_value(e.value)) def print_table_data(): table.sync_data_to_client() table.run_table_method("print", True) u.button("print table data", on_click=print_table_data) ``` -------------------------------- ### Create Table from Pandas DataFrame Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Initialize a Tabulator table directly from a pandas DataFrame. Column definitions can be updated subsequently. ```python from nicegui_tabulator import tabulator import pandas as pd df = pd.DataFrame( { "name": ["Alice", "Bob", "Charlie"], "age": [25, 30, 35], "color": ["blue", "red", "green"], "dob": [None, "2021-01-01", "2021-02-02"], } ) tabulator.from_pandas(df) ``` ```python tabulator.from_pandas(df).update_column_definition( "age", {"hozAlign": "left", "formatter": "progress"} ) ``` -------------------------------- ### tabulator.from_pandas Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Creates a Tabulator table directly from a pandas DataFrame. Column definitions can be updated immediately after creation using the update_column_definition method. ```APIDOC ## tabulator.from_pandas ### Description Creates a Tabulator table directly from a pandas DataFrame. Column definitions can be updated immediately after creation using the update_column_definition method. ### Method POST ### Endpoint /tabulator/from_pandas ### Parameters #### Request Body - **df** (pandas.DataFrame) - Required - The pandas DataFrame to convert into a Tabulator table. ### Request Example ```python import pandas as pd from nicegui_tabulator import tabulator df = pd.DataFrame({ "name": ["Alice", "Bob", "Charlie"], "age": [25, 30, 35], }) tabulator.from_pandas(df).update_column_definition("age", {"hozAlign": "left"}) ``` ### Response #### Success Response (200) - **tabulator_instance** (object) - The created Tabulator table instance. ``` -------------------------------- ### add_cell_slot Source: https://github.com/crystalwindsnake/nicegui-tabulator/blob/main/README.md Decorator to define a custom cell renderer for a specific column. It allows embedding NiceGUI components within table cells and handling their interactions. ```APIDOC ## add_cell_slot ### Description Decorator to define a custom cell renderer for a specific column. It allows embedding NiceGUI components within table cells and handling their interactions. ### Method POST ### Endpoint /tabulator/{column_name}/cell_slot ### Parameters #### Path Parameters - **column_name** (string) - Required - The name of the column for which to define the cell slot. #### Request Body - **cell_renderer_function** (function) - Required - A function that takes `CellSlotProps` and returns a NiceGUI component to be rendered in the cell. ### Request Example ```python from nicegui_tabulator import tabulator, CellSlotProps from nicegui import ui table = tabulator({...}) @table.add_cell_slot("name") def _(props: CellSlotProps): ui.input(value=props.value, on_change=lambda e: props.update_value(e.value)) ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful registration of the cell slot. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.