【问题标题】:django-tables2 column right justifydjango-tables2 列右对齐
【发布时间】:2016-03-06 19:56:47
【问题描述】:

我正在使用django-tables2 显示一个包含整数值的表,并且想知道如何右对齐列。

tables.py 中是否有参数/属性?

下面是显示的内容:

【问题讨论】:

    标签: django django-tables2


    【解决方案1】:

    生成的 html 中的所有 tdth 元素都将列名作为类属性。这样您就可以轻松地引用 CSS 中的列。

    此外,您可以通过将关键字参数attrs 传递给Column 的定义来为thtd 单元格元素提供属性,如docs 中所述:

    class SimpleTable(tables.Table):
        name = tables.Column(
            attrs={
                "th": {"id": "foo"},
                "td": {"align": "right"}
            }
        )
    

    此列的thtd 元素将如下所示:

    <th id="foo" class="name"> ... </th>
    <td align="right" class="name"> ... </td>
    

    【讨论】:

    • 这对我有用:'td':{'style':'text-align: right;'}
    • 对我来说两者的结合都有效:attrs={'th': {'style':'text-align: right;'}, 'td': {'align': 'right'}}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 2017-03-07
    • 2011-04-09
    相关资源
    最近更新 更多