2016-11-09 165 views
0

谁能告诉我如何将垂直滚动条添加到django-tables2,而不必垂直滚动条的Django tables2

Page 1 of 2 Next 25 of 49 vehicles

在表的底部。

tables.py

''' 
Created on 28 Oct 2016 

@author: JXA8341 
''' 
import django_tables2 as tables 
from .models import Vehicle 

class CheckBoxColumnWithName(tables.CheckBoxColumn): 
    @property 
    def header(self): 
     return self.verbose_name 

class VehicleTable(tables.Table): 

    update = tables.CheckBoxColumn(accessor="pk", 
            attrs = { "th__input":{"onclick": "toggle(this)"}}, 
            orderable=False) 

    class Meta: 
     model = Vehicle 
     fields = ('update', 'vehid') 

     # Add class="paleblue" to <table> tag 
     attrs = {'class':'paleblue'} 

screen.css

table.paleblue + ul.pagination { 
    font: normal 11px/14px 'Lucida Grande', Verdana, Helvetica, Arial, sans- serif; 
    overflow: scroll; 
    margin: 0; 
    padding: 10px; 
    border: 1px solid #DDD; 
    list-style: none; 
    } 
div.table-container { 
    display: inline-block; 
    position:relative; 
    overflow:auto; 
    } 

table.html

<div class='vehlist'> 
    <script language="JavaScript"> 
     function toggle(source) { 
      checkboxes = document.getElementsByName('update'); 
      for(var i in checkboxes) 
       checkboxes[i].checked = source.checked; 
     } 
    </script> 
     <form action="/loadlocndb/" method="POST" enctype="multipart/form-data"> 
      {% csrf_token %} 
      {% render_table veh_list %} 



      <h4> Location database .csv file</h4> 
      {{ form.locndb }} 
      <input type="submit" value="Submit" /> 
     </form> 
    </div> 

我看了所有的地方,但我似乎无法获得直答案,还是有更好的表模块,我可以用来显示数组和复选框?

回答

0

对于同一条船上的任何人我都明白了。

我转身禁用分页

RequestConfig(request, pagination=False).configure(veh_list)

然后我裹在<div>表在HTML模板

<div style="width: 125px; height: 500px; overflow-y: scroll;"> 
     {% render_table veh_list %} 
</div> 

<div>然后添加一个滚动条到整个表格的界面,我个人本来希望将头部不断放在顶部,但这是我能想出的最佳解决方案。