{# Shadcn-style Table Component for FastAPI Shadcn Admin Data table with sorting, actions, and responsive design. #} {% macro table(class="") %}
{{ caller() }}
{% endmacro %} {% macro thead(class="") %} {{ caller() }} {% endmacro %} {% macro tbody(class="") %} {{ caller() }} {% endmacro %} {% macro tr(class="") %} {{ caller() }} {% endmacro %} {% macro th(text="", sortable=false, sort_url="", current_sort="", class="") %} {% if sortable and sort_url %} {{ text if text else caller() }} {% if current_sort == 'asc' %} {% elif current_sort == 'desc' %} {% else %} {% endif %} {% else %} {{ text if text else caller() }} {% endif %} {% endmacro %} {% macro td(class="") %} {{ caller() }} {% endmacro %} {# Data table with headers and rows #} {% macro data_table(columns, rows, model_name, id_field="id", edit_url_template="", delete_url_template="") %} {% import "components/buttons.html" as buttons %} {% call table() %} {% call thead() %} {% call tr() %} {% for col in columns %} {{ th(text=col.label, sortable=col.get('sortable', false), sort_url=col.get('sort_url', ''), current_sort=col.get('current_sort', '')) }} {% endfor %} {{ th(text="Actions", class="text-right") }} {% endcall %} {% endcall %} {% call tbody() %} {% for row in rows %} {% call tr() %} {% for col in columns %} {% call td() %} {{ row[col.field] }} {% endcall %} {% endfor %} {% call td(class="text-right") %}
{% if edit_url_template %} {% endif %} {% if delete_url_template %} {% endif %}
{% endcall %} {% endcall %} {% else %} {% call tr() %} {% call td(class="text-center py-8 text-muted-foreground") %} No records found {% endcall %} {% endcall %} {% endfor %} {% endcall %} {% endcall %} {% endmacro %} {# Pagination component #} {% macro pagination(page, total_pages, base_url) %} {% endmacro %}