Created
February 16, 2023 23:41
-
-
Save Diegiwg/f85e007d243c96c9576016bb903ced93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nicegui import ui | |
from requests import get | |
from quasar import * | |
table = table() | |
table.selection.type("single") | |
table.columns.add("title", "Title", "title") | |
table.columns.add("completed", "Completed", "completed") | |
ui.button("Add ID column", on_click=lambda: table.columns.add("id", "id", "id")) | |
req = get("https://jsonplaceholder.typicode.com/todos") | |
todos = req.json() | |
for todo in todos: | |
table.rows.add(todo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nicegui.element import Element | |
class columns: | |
itens = [] | |
def __init__(self, parent: Element) -> None: | |
self.parent = parent | |
def add(self, name: str, label: str, field: str): | |
self.itens.append({"name": name, "label": label, "field": field}) | |
self.parent.update() | |
class rows: | |
data = [] | |
def __init__(self, parent: Element) -> None: | |
self.parent = parent | |
def add(self, data: dict): | |
self.data.append(data) | |
self.parent.update() | |
class selection: | |
def __init__(self, parent: Element) -> None: | |
self.parent = parent | |
self.parent._props["selected"] = [] | |
def type(self, type: str): | |
self.parent._props["selection"] = type | |
class QTable(Element): | |
def __init__(self) -> None: | |
super().__init__("q-table") | |
self.columns = columns(self) | |
self._props["columns"] = self.columns.itens | |
self.rows = rows(self) | |
self._props["rows"] = self.rows.data | |
self.selection = selection(self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment