Flask Admin 在表视图中右对齐值

问题描述 投票:0回答:1

使用Flask Admin包查看数据库表,如何使单元格中的值右对齐?请参阅下面的代码。

class VwSalesByPersonYearView(MyModelView):
    """VwSalesByPersonYear model view"""

    can_create = False
    can_edit = False
    can_delete = False
    column_display_pk = False
    can_set_page_size = True
    page_size = 50

    column_list = (
        "service_year",
        "name_",
        "sales_total",
    )
    column_labels = {
        "service_year": "Year",
        "name_": "Employee",
        "sales_total": "Total Sales",
    }
    column_descriptions = {
        "service_year": "Year of the sales",
        "sales_total": "Total sales (i.e. labour + parts)",
    }
    column_sortable_list = (
        "service_year",
        "name_",
        "sales_total",
    )
    column_default_sort = [
        ("service_year", True),
        ("sales_total", True),
        ("name_", True),
    ]
    column_filters = (
        "service_year",
        "name_",
        "sales_total",
    )
    column_searchable_list = (
        "service_year",
        "name_",
    )
    column_formatters = {
        "service_year": lambda v, c, m, n: f"{m.service_year:.0f}",
        "sales_total": lambda v, c, m, n: f"{m.sales_total or 0:,.0f}",
    }
html flask flask-admin
1个回答
0
投票

我找到了一个解决方案:在column_formatters中使用

Markup
style="text-align: right;"

    column_formatters = {
        "service_year": lambda v, c, m, n: f"{m.service_year:.0f}",
        "sales_total": lambda v, c, m, n: Markup(f'<div style="text-align: right;">{m.sales_total or 0:,.0f}</div>'),
    }
© www.soinside.com 2019 - 2024. All rights reserved.