【问题标题】:Disable pagination in django-tables2?在 django-tables2 中禁用分页?
【发布时间】:2012-12-26 04:26:13
【问题描述】:

我有一张我不想分页的表格。我没有指定分页,如文档所示:

table.paginate(page=request.GET.get('page', 1), per_page=25)

表格仍然分页,大概是默认情况下。 RequestConfig 类文档字符串说要为分页传递一个错误值以禁用分页,但我对此很模糊。以下是我在视图类中尝试过的选项:

my_table.paginate = False
RequestConfig(request).configure(my_table, paginate=False)
RequestConfig(request).configure(my_table).paginate(False)
RequestConfig(request).configure(my_table, {table.paginate:False})
RequestConfig(request).configure(my_table, {paginate:False})
RequestConfig(request).configure(my_table, {"paginate":False})

【问题讨论】:

    标签: django-tables2 django tags django-tables2


    【解决方案1】:

    你想做的事:

    RequestConfig(request, paginate=False).configure(my_table)
    

    【讨论】:

      【解决方案2】:

      如果您使用基于类的 Django 视图,只需覆盖视图类中的 get_table_pagination 方法和表类中的 get_caption_display 方法:

      class YourView(SingleTableMixin, generic.TemplateView):
          def get_table_pagination(self):
              return False
      

      在你的表类中,

      class YourTable(Table):
          def get_caption_display(self):
              return False
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-25
        • 1970-01-01
        • 2021-09-29
        • 2015-06-15
        • 1970-01-01
        相关资源
        最近更新 更多