Skip to content

Commit

Permalink
Sortable to tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac-Flath committed Oct 16, 2024
1 parent 92b80a3 commit cf9acc3
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 116 deletions.
71 changes: 37 additions & 34 deletions ex_nbs/01_tasks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 130,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 131,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -30,12 +30,13 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"from fasthtml.common import *\n",
"import fasthtml.common as fh\n",
"from fh_frankenui.core import *\n",
"from fh_frankenui.components import *\n",
"from fasthtml.svg import *\n",
Expand All @@ -44,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -54,7 +55,7 @@
"from uuid import uuid4\n",
"from IPython.display import display, HTML\n",
"\n",
"if is_port_free(8000) and IN_NOTEBOOK::\n",
"if is_port_free(8000) and IN_NOTEBOOK:\n",
" app, rt = fh.fast_app(pico=False, hdrs=Theme.blue.headers())\n",
" server = JupyUvi(app)\n",
"def HShow(comp, app):\n",
Expand All @@ -69,7 +70,7 @@
},
{
"cell_type": "code",
"execution_count": 134,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -124,7 +125,7 @@
},
{
"cell_type": "code",
"execution_count": 135,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -135,7 +136,7 @@
},
{
"cell_type": "code",
"execution_count": 136,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -156,7 +157,7 @@
},
{
"cell_type": "code",
"execution_count": 137,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -169,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count": 138,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -184,7 +185,7 @@
},
{
"cell_type": "code",
"execution_count": 145,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -209,7 +210,7 @@
},
{
"cell_type": "code",
"execution_count": 140,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -222,7 +223,7 @@
},
{
"cell_type": "code",
"execution_count": 141,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -241,17 +242,17 @@
" <div class=\"uk-nav-subtitle uk-text-muted uk-text-small\">[email protected]</div>\n",
" </li>\n",
" <li class=\"uk-nav-divider \"></li>\n",
" <li>\n",
"<a href=\"#\" class=\"uk-drop-close justify-between\">Profile<span class=\"uk-text-muted uk-text-small\">⇧⌘P</span></a> </li>\n",
" <li>\n",
"<a href=\"#\" class=\"uk-drop-close justify-between\">Billing<span class=\"uk-text-muted uk-text-small\">⌘B</span></a> </li>\n",
" <li>\n",
"<a href=\"#\" class=\"uk-drop-close justify-between\">Settings<span class=\"uk-text-muted uk-text-small\">⌘S</span></a> </li>\n",
" <li>\n",
"<a href=\"#\" class=\"uk-drop-close justify-between\">New Team<span class=\"uk-text-muted uk-text-small\"></span></a> </li>\n",
" <li class=\"uk-drop-close \">\n",
"<a href=\"#\" class=\"justify-between\">Profile<span class=\"uk-text-muted uk-text-small\">⇧⌘P</span></a> </li>\n",
" <li class=\"uk-drop-close \">\n",
"<a href=\"#\" class=\"justify-between\">Billing<span class=\"uk-text-muted uk-text-small\">⌘B</span></a> </li>\n",
" <li class=\"uk-drop-close \">\n",
"<a href=\"#\" class=\"justify-between\">Settings<span class=\"uk-text-muted uk-text-small\">⌘S</span></a> </li>\n",
" <li class=\"uk-drop-close \">\n",
"<a href=\"#\" class=\"justify-between\">New Team<span class=\"uk-text-muted uk-text-small\"></span></a> </li>\n",
" <li class=\"uk-nav-divider \"></li>\n",
" <li>\n",
"<a href=\"#\" class=\"uk-drop-close justify-between\">Logout<span class=\"uk-text-muted uk-text-small\"></span></a> </li>\n",
" <li class=\"uk-drop-close \">\n",
"<a href=\"#\" class=\"justify-between\">Logout<span class=\"uk-text-muted uk-text-small\"></span></a> </li>\n",
" </ul>\n",
" </div>\n",
" </div>\n",
Expand All @@ -261,7 +262,7 @@
"<IPython.core.display.HTML object>"
]
},
"execution_count": 141,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -272,7 +273,7 @@
},
{
"cell_type": "code",
"execution_count": 142,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -289,7 +290,7 @@
},
{
"cell_type": "code",
"execution_count": 143,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand All @@ -303,7 +304,7 @@
"button(('Create Task',),{'type': 'button', 'uk-toggle': 'target: #TaskForm', 'class': 'uk-button uk-button-primary uk-text-bold uk-text-small'})"
]
},
"execution_count": 143,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -314,7 +315,7 @@
},
{
"cell_type": "code",
"execution_count": 144,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -343,7 +344,7 @@
"<IPython.core.display.HTML object>"
]
},
"execution_count": 144,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -361,7 +362,7 @@
},
{
"cell_type": "code",
"execution_count": 123,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -378,7 +379,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 17,
"metadata": {
"scrolled": true
},
Expand All @@ -395,7 +396,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -413,7 +414,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 19,
"metadata": {
"scrolled": false
},
Expand All @@ -426,7 +427,9 @@
" header_data=task_columns,\n",
" body_data=data,\n",
" body_cell_render=cell_render,\n",
" header_cell_render=header_render))\n"
" header_cell_render=header_render,\n",
" sortable=True\n",
"))\n"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion ex_nbs/02_cards.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@
"def page():\n",
" return Title(\"Custom\"),Grid(\n",
" *map(Div,(Left1,Left2,Middle1,Middle2,Middle3,Middle4,Right1,Right2, Right3)),\n",
" cols=1, cls=(GridT.small,'md:grid-cols-3', 'sm:grid-cols-2'), uk_grid=\"masonry: pack\")"
" cols=1, cls=(GridT.small,'md:grid-cols-3', 'sm:grid-cols-2'), \n",
" uk_grid=\"masonry: next\")\n"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion ex_nbs/app/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@
def page():
return Title("Custom"),Grid(
*map(Div,(Left1,Left2,Middle1,Middle2,Middle3,Middle4,Right1,Right2, Right3)),
cols=1, cls=(GridT.small,'md:grid-cols-3', 'sm:grid-cols-2'), uk_grid="masonry: pack")
cols=1, cls=(GridT.small,'md:grid-cols-3', 'sm:grid-cols-2'),
uk_grid="masonry: next")


# %% ../02_cards.ipynb
cards_homepage = page()
5 changes: 4 additions & 1 deletion ex_nbs/app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# %% ../01_tasks.ipynb
from fasthtml.common import *
import fasthtml.common as fh
from fh_frankenui.core import *
from fh_frankenui.components import *
from fasthtml.svg import *
Expand Down Expand Up @@ -110,7 +111,9 @@ def _Td(*args,cls='', **kwargs): return Td(*args, cls=f'p-2 {cls}',**kwargs)
header_data=task_columns,
body_data=data,
body_cell_render=cell_render,
header_cell_render=header_render))
header_cell_render=header_render,
sortable=True
))


# %% ../01_tasks.ipynb
Expand Down
13 changes: 8 additions & 5 deletions fh_frankenui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,28 +724,31 @@ def Th(*args,**kwargs): return _TableCell(fh.Th, *args, **kwargs)

def Tr(*cells, cls=(), **kwargs): return fh.Tr(*cells, cls=stringify(cls), **kwargs)
def Thead(*rows, cls=(), **kwargs): return fh.Thead(*rows, cls=stringify(cls), **kwargs)
def Tbody(*rows, cls=(), **kwargs): return fh.Tbody(*rows, cls=stringify(cls), **kwargs)
def Tbody(*rows, cls=(), sortable=False, **kwargs): return fh.Tbody(*rows, cls=stringify(cls), uk_sortable=sortable, **kwargs)

# %% ../lib_nbs/01_core.ipynb
def TableFromLists(header_data, body_data, footer_data=None,
header_cell_render=Th,body_cell_render=Td, footer_cell_render=Td,
cls=(TableT.middle, TableT.divider, TableT.hover, TableT.small), **kwargs):
cls=(TableT.middle, TableT.divider, TableT.hover, TableT.small),
sortable=False, **kwargs):

return Table(
Thead(Tr(*map(header_cell_render, header_data))),
Tbody(*[Tr(*map(body_cell_render, r)) for r in body_data]),
Tbody(*[Tr(*map(body_cell_render, r)) for r in body_data], sortable=sortable),
Tfoot(Tr(*map(footer_cell_render, footer_data))) if footer_data else '',
cls=stringify(cls),
**kwargs)

# %% ../lib_nbs/01_core.ipynb
def TableFromDicts(header_data:Sequence, body_data:Sequence[dict], footer_data=None,
header_cell_render=Th, body_cell_render=lambda k,v : Td(v), footer_cell_render=lambda k,v : Td(v),
cls=(TableT.middle, TableT.divider, TableT.hover, TableT.small), **kwargs):
cls=(TableT.middle, TableT.divider, TableT.hover, TableT.small),
sortable=False,
**kwargs):

return Table(
Thead(Tr(*[header_cell_render(h) for h in header_data])),
Tbody(*[Tr(*[body_cell_render(k, r) for k in header_data]) for r in body_data]),
Tbody(*[Tr(*[body_cell_render(k, r) for k in header_data]) for r in body_data], sortable=sortable),
Tfoot(Tr(*[footer_cell_render(k, footer_data.get(k.lower(), '')) for k in header_data])) if footer_data else '',
cls=stringify(cls),
**kwargs
Expand Down
Loading

0 comments on commit cf9acc3

Please sign in to comment.