[英]How to define dynamic number of columns in django-datatables-view
I'm using the django-datatables-view (that is used in conjunction with the jQuery plugin DataTables). 我正在使用django-datatables-view(与jQuery插件DataTables结合使用)。 For normal use, I create a class-based view based on BaseDatatableView and define there the columns variable:
对于正常使用,我基于BaseDatatableView创建一个基于类的视图,并在其中定义column变量:
class MyCBV(LoginRequiredMixin, BaseDatatableView):
model = myModel
columns = ['my_model_column1','my_model_column2']
...
Now I would like to create a variable number of columns that is based on a parameter. 现在,我想基于参数创建可变数量的列。 I can access the parameter in the CBV functions but it seems I cannot overwrite the columns variable.
我可以访问CBV 函数中的参数,但似乎无法覆盖column变量。 For example, I tried to overwrite the columns variable in get_context_data function but columns retains its original value later in render_column function.
例如,我试图覆盖get_context_data函数中的columns变量,但是column稍后在render_column函数中保留其原始值。
Somebody has a solution? 有人有解决办法吗?
BaseDatatableView
implements DatatableMixin
which has a method get_columns
with a default implementation of BaseDatatableView
实现了DatatableMixin
,它具有方法get_columns
,其默认实现为
def get_columns(self):
""" Returns the list of columns that are returned in the result set
"""
return self.columns
You can override it and pass your custom columns here (using your parameter) 您可以覆盖它并在此处传递自定义列(使用您的参数)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.