Infinite Scroll
Demonstrates infinite scrolling of a page
from fasthtml.common import Div, Table, Tbody, Td, Th, Thead, Tr, fast_app
app, rt = fast_app()
@app.get
def page():
return Div(cls="container")(
Table(
Thead(Tr(Th("Name"), Th("ID"))),
Tbody(load_contacts(page=1)),
),
)
@app.get
def load_contacts(page: int, limit: int = 5):
rows = [Tr(Td("Smith"), Td((page - 1) * limit + i)) for i in range(1, limit)]
return *rows, make_last_row(page, limit)
def make_last_row(page, limit):
return Tr(hx_trigger="revealed", hx_swap="afterend", hx_get=load_contacts.rt(page=page + 1))(
Td("Smith"),
Td(page * limit),
)