【问题标题】:django tables2 display sort arrows on headerdjango tables2 在标题上显示排序箭头
【发布时间】:2020-02-12 17:50:05
【问题描述】:

我正在使用 django tables2,并且我认为在标题列上使用向上和向下箭头来指示当前的排序顺序会很有用,尤其是当默认排序在第一个以外的列上时。

尝试使用 CSS 但没有成功,有什么建议或示例说明如何做到这一点?

【问题讨论】:

    标签: css django django-tables2


    【解决方案1】:

    this question 中提供的答案可能会解决您的问题,但如果不知道您已经使用 CSS 尝试过什么,就很难确定。

    templates that come built-in 和 django-tables2 都将列属性呈现到最终的 HTML,因此定义为 orderable=True 的列将生成带有 "orderable" 类的列标题标签(例如 <th class="orderable">)。此外,已选择升序或降序排序的列将在渲染时添加 ascdesc 类标识符。

    因此,您可以设置一个 CSS 规则,根据可排序列的状态呈现三个不同的箭头图像:

    table.table thead th.orderable {
        background: url(path_to_unsorted_indicator_image)
    }
    
    table.table thead th.asc.orderable {
        background: url(path_to_ascending_indicator_image)
    }
    
    table.table thead th.desc.orderable {
        background: url(path_to_descending_indicator_image)
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-06
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多