nicegui-tabulator


Namenicegui-tabulator JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryThis is a Python package that provides a simple way to create tables using the Tabulator library. It is built on top of the NiceGUI library.
upload_time2024-12-14 14:07:23
maintainerNone
docs_urlNone
authorCrystalWindSnake
requires_python<4.0,>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## NiceGUI Tabulator

This is a Python package that provides a simple way to create tables using the [Tabulator](https://github.com/olifolkerd/tabulator) library. It is built on top of the [NiceGUI](https://github.com/zauberzeug/nicegui) library.


<div align="center">

English| [简体中文](./README.zh-CN.md)

</div>

## Features

- ✅Easily utilize various events and methods from the Tabulator library.
- ✅Built-in themes for Bootstrap 4 and Material Design.[Example](#use_theme)
- ✅Cell Slots: Place any NiceGUI component within a cell and access all its functionalities without writing string templates. [Example](#cell-slot)
- ✅Built-in support for creating tables from pandas data. [Example](#from_pandas)
- 🔲Built-in support for downloading in formats such as Excel, PDF, etc.
- 🔲Row Slots


## Installation

```
pip install nicegui-tabulator
```

## Usage

```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"},
        ],
    )


ui.button("sort", on_click=on_sort)

```

---

## API

### from_pandas
create from pandas dataframe:

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

---

You can update column configurations immediately after creating the table.


```python
tabulator.from_pandas(df).update_column_definition(
    "age", {"hozAlign": "left", "formatter": "progress"}
)
```


---

### Cell Slot

Cell Slots allow you to place any NiceGUI component within a cell and access all its functionalities without writing string templates.

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

ui.button("print table data", on_click=print_table_data)
```

---

### use_theme

```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')
```
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "nicegui-tabulator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "CrystalWindSnake",
    "author_email": "568166495@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/37/55/103b9da792c7a964ade2ffb996665d6724b98b99927134517a749d005487/nicegui_tabulator-0.2.1.tar.gz",
    "platform": null,
    "description": "## NiceGUI Tabulator\n\nThis is a Python package that provides a simple way to create tables using the [Tabulator](https://github.com/olifolkerd/tabulator) library. It is built on top of the [NiceGUI](https://github.com/zauberzeug/nicegui) library.\n\n\n<div align=\"center\">\n\nEnglish| [\u7b80\u4f53\u4e2d\u6587](./README.zh-CN.md)\n\n</div>\n\n## Features\n\n- \u2705Easily utilize various events and methods from the Tabulator library.\n- \u2705Built-in themes for Bootstrap 4 and Material Design.[Example](#use_theme)\n- \u2705Cell Slots: Place any NiceGUI component within a cell and access all its functionalities without writing string templates. [Example](#cell-slot)\n- \u2705Built-in support for creating tables from pandas data. [Example](#from_pandas)\n- \ud83d\udd32Built-in support for downloading in formats such as Excel, PDF, etc.\n- \ud83d\udd32Row Slots\n\n\n## Installation\n\n```\npip install nicegui-tabulator\n```\n\n## Usage\n\n```python\nfrom nicegui_tabulator import tabulator\nfrom nicegui import ui\n\ntabledata = [\n    {\"id\": 1, \"name\": \"Oli Bob\", \"age\": \"12\", \"col\": \"red\", \"dob\": \"\"},\n    {\"id\": 2, \"name\": \"Mary May\", \"age\": \"1\", \"col\": \"blue\", \"dob\": \"14/05/1982\"},\n    {\n        \"id\": 3,\n        \"name\": \"Christine Lobowski\",\n        \"age\": \"42\",\n        \"col\": \"green\",\n        \"dob\": \"22/05/1982\",\n    },\n    {\n        \"id\": 4,\n        \"name\": \"Brendon Philips\",\n        \"age\": \"125\",\n        \"col\": \"orange\",\n        \"dob\": \"01/08/1980\",\n    },\n    {\n        \"id\": 5,\n        \"name\": \"Margret Marmajuke\",\n        \"age\": \"16\",\n        \"col\": \"yellow\",\n        \"dob\": \"31/01/1999\",\n    },\n]\n\ntable_config = {\n    \"height\": 205,  \n    \"data\": tabledata, \n    \"columns\": [  \n        {\"title\": \"Name\", \"field\": \"name\", \"width\": 150, \"headerFilter\": \"input\"},\n        {\"title\": \"Age\", \"field\": \"age\", \"hozAlign\": \"left\", \"formatter\": \"progress\"},\n        {\"title\": \"Favourite Color\", \"field\": \"col\"},\n        {\n            \"title\": \"Date Of Birth\",\n            \"field\": \"dob\",\n            \"sorter\": \"date\",\n            \"hozAlign\": \"center\",\n        },\n    ],\n}\n\ntable = tabulator(table_config).on_event(\"rowClick\", lambda e: ui.notify(e))\n\n\ndef on_sort():\n    table.run_table_method(\n        \"setSort\",\n        [\n            {\"column\": \"name\", \"dir\": \"desc\"},\n            {\"column\": \"age\", \"dir\": \"asc\"},\n        ],\n    )\n\n\nui.button(\"sort\", on_click=on_sort)\n\n```\n\n---\n\n## API\n\n### from_pandas\ncreate from pandas dataframe:\n\n```python\nfrom nicegui_tabulator import tabulator\nimport pandas as pd\n\n\ndf = pd.DataFrame(\n    {\n        \"name\": [\"Alice\", \"Bob\", \"Charlie\"],\n        \"age\": [25, 30, 35],\n        \"color\": [\"blue\", \"red\", \"green\"],\n        \"dob\": [None, \"2021-01-01\", \"2021-02-02\"],\n    }\n)\n\n\ntabulator.from_pandas(df)\n```\n\n---\n\nYou can update column configurations immediately after creating the table.\n\n\n```python\ntabulator.from_pandas(df).update_column_definition(\n    \"age\", {\"hozAlign\": \"left\", \"formatter\": \"progress\"}\n)\n```\n\n\n---\n\n### Cell Slot\n\nCell Slots allow you to place any NiceGUI component within a cell and access all its functionalities without writing string templates.\n\n```python\nfrom nicegui import ui\nfrom nicegui_tabulator import tabulator, CellSlotProps\n\n\ntabledata = [\n    {\"id\": 1, \"name\": \"bar\", \"age\": \"12\"},\n    {\"id\": 2, \"name\": \"foo\", \"age\": \"1\"},\n]\n\ntable_config = {\n    \"data\": tabledata,\n    \"columns\": [\n        {\"title\": \"Name\", \"field\": \"name\"},\n        {\"title\": \"Age\", \"field\": \"age\"},\n    ],\n    \"printConfig\": {\n        \"formatCells\": False,\n    },\n}\n\ntable = tabulator(table_config)\n\n\n@table.add_cell_slot(\"name\")\ndef _(props: CellSlotProps):\n    # This function is called when rendering the cell of the table, and it receives the properties of the cell,\n    # including the value of the cell, row index, column name, etc.\n    # 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`).\n    ui.input(value=props.value, on_change=lambda e: props.update_value(e.value))\n\n\n@table.add_cell_slot(\"age\")\ndef _(props: CellSlotProps):\n    ui.number(value=props.value, min=0, max=100,on_change=lambda e: props.update_value(e.value))\n\n\ndef print_table_data():\n    table.sync_data_to_client()\n    table.run_table_method(\"print\", True)\n\nui.button(\"print table data\", on_click=print_table_data)\n```\n\n---\n\n### use_theme\n\n```python\nfrom nicegui_tabulator import tabulator, use_theme\n\n# use the theme for all clients\nuse_theme('bootstrap4')\n\n# use the theme only for the current client\nuse_theme('bootstrap4', shared=False)\n\n@ui.page('/')\ndef my_page():\n    # use the theme only for this page\n    use_theme('bootstrap4')\n```",
    "bugtrack_url": null,
    "license": null,
    "summary": "This is a Python package that provides a simple way to create tables using the Tabulator library. It is built on top of the NiceGUI library.",
    "version": "0.2.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cacec5dcbd9ba826d456d29806089a6dc3a6d807e2c0e0df6aa2c995c95629f9",
                "md5": "bdb91ff71e44295415403d552a6ea90c",
                "sha256": "8b1329dbf62e64b8ec0667cf90c30b846e5e55cd72c83df6f12e793f399df82e"
            },
            "downloads": -1,
            "filename": "nicegui_tabulator-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bdb91ff71e44295415403d552a6ea90c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 173225,
            "upload_time": "2024-12-14T14:07:20",
            "upload_time_iso_8601": "2024-12-14T14:07:20.952972Z",
            "url": "https://files.pythonhosted.org/packages/ca/ce/c5dcbd9ba826d456d29806089a6dc3a6d807e2c0e0df6aa2c995c95629f9/nicegui_tabulator-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3755103b9da792c7a964ade2ffb996665d6724b98b99927134517a749d005487",
                "md5": "a8b2d65c365cf44ebc317012b601f958",
                "sha256": "e99ef4b8f17cad12a4f43d5109610ee5c41342d425f9c42477232f7b78f5017f"
            },
            "downloads": -1,
            "filename": "nicegui_tabulator-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a8b2d65c365cf44ebc317012b601f958",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 154609,
            "upload_time": "2024-12-14T14:07:23",
            "upload_time_iso_8601": "2024-12-14T14:07:23.842336Z",
            "url": "https://files.pythonhosted.org/packages/37/55/103b9da792c7a964ade2ffb996665d6724b98b99927134517a749d005487/nicegui_tabulator-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-14 14:07:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nicegui-tabulator"
}
        
Elapsed time: 0.40299s