import htmltools as html
from reactable.data import cars_93
from reactable import Reactable, Column, embed_css
embed_css()
= cars_93[20:25, ["manufacturer", "model", "type", "price"]] data
Custom rendering (python)
Cells
from reactable.models import CellInfo
def fmt_cell_red(ci: CellInfo):
return html.div(ci.value.upper(), style="color: red")
Reactable(
data,={"manufacturer": Column(cell=fmt_cell_red)},
columns )
Headers
from reactable.models import HeaderCellInfo
def fmt_header(ci: HeaderCellInfo):
return html.div(f"name: {ci.name}", html.br(), f"value: {ci.value}")
Reactable(
data,={"manufacturer": Column(header=fmt_header, name="Manufacturer")},
columns )
Expandable row details
from reactable.models import RowInfo
# TODO: explain use of to_widget
def fmt_details(ci: RowInfo):
return html.div(
f"Details for row: {ci.row_index}",
Reactable(data[ci.row_index, :]).to_widget(),
)
Reactable("model"]],
data[[=fmt_details,
details )
Why use javascript? Dynamic filtering
from reactable.models import JS
= JS(
js_footer """
function(column, state) {
let total = 0
state.sortedData.forEach(function(row) {
total += row[column.id]
})
return '<b>$' + total.toFixed(2) + '</b>'
}"""
)
Reactable(
data,=True,
searchable={
columns"price": Column(
=True,
html=js_footer,
footer
),
}, )