简体   繁体   English

django-tables2:将滚动条添加到表

[英]django-tables2: Add scroll bar to table

I've created a table using django-tables2: 我已经使用django-tables2创建了一个表:

class MyTable(tables.Table):
    class Meta:
        model = TestModel
        attrs = {"class": "paleblue"}

In this table, I noticed that when any given cell contains too many characters, the column width will automatically expand. 在此表中,我注意到当任何给定的单元格包含太多字符时,列宽将自动扩展。 This can sometimes expand outside my browser's view-able area. 有时这可能会扩展到我的浏览器的可见区域之外。 I tried to add a scroll bar by modifying the default screen.css file provided by django-tables2 (added overflow: scroll ): 我试图通过修改django-tables2提供的默认screen.css文件来添加滚动条(添加了overflow: scroll ):

table.paleblue + ul.pagination {
    background: white url(../img/pagination-bg.gif) left 180% repeat-x;
    overflow: scroll;
    margin: 0;
    padding: 10px;
    border: 1px solid #DDD;
    list-style: none;
}

Although this adds the scroll bar, the right-side of the scroll bar expands along with the table. 尽管这会添加滚动条,但滚动条的右侧会随表格一起扩展。 Thus I cannot see the right-half of the scroll bar. 因此,我看不到滚动条的右半部分。 Also, the scroll bar doesn't appear to be 'active' in that there is no 'bar' to click on. 另外,滚动条似乎没有处于“活动”状态,因为没有单击的“条”。

What is the correct way to implement a scroll bar inside a django-tables2 table? 在django-tables2表中实现滚动条的正确方法是什么?

I found the solution after some trial and error. 经过反复尝试,我找到了解决方案。 I had to modify the following entry in the django-tables2's default screen.css file: 我必须在django-tables2的默认screen.css文件中修改以下条目:

div.table-container {
    display: inline-block;
    position:relative;
    overflow:auto;
}

I hope this solution is helpful to others. 我希望此解决方案对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM