Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

(tables) Functionality to dynamically add/remove columns displayed?

6 views
Skip to first unread message

SnappyDjangoUser

unread,
Jan 7, 2009, 6:21:06 PM1/7/09
to Django Apps
I am interested in adding functionality to my django application which
will allow a user to select which table columns they would like
displayed in the table. I am evaluating django-tables to see if it
will help solve my problem. I see documentation which shows how you
can hard code each table column as visible or hidden based on the
model definition.

i.e. column "population" is always hidden and not displayed in the
table.
class CountryTable(tables.Table):
name = tables.Column(verbose_name="Country Name")
population = tables.Column(sortable=False, visible=False)
time_zone = tables.Column(name="tz", default="UTC+1")

Does django-tables provide functionality to dynamically change the
columns displayed based on user preference?

Thanks,

Brian

Michael Elsdörfer

unread,
Jan 9, 2009, 8:20:30 PM1/9/09
to Django Apps
> Does django-tables provide functionality to dynamically change the
> columns displayed based on user preference?

There currently is no functionality that is specifically geared
towards your scenario, though you can of course change the visibility
of columns at any time. In other words, something like this does not
exist:

countries = CountryTable(qs, visibility=request.GET.get('visibility-
options')

Instead, you need to parse the users preferences yourself and update
the column visibilities:

countries = CountryTable(queryset)
for column_name, state in visibility_options:
countries.columns[column_name].visible = state

Note that due to a bug that I just fixed the above only works since
rev. 42.

Michael

Brian Wallace

unread,
Jan 12, 2009, 1:56:28 PM1/12/09
to djang...@googlegroups.com
Thanks Michael!  I think django-tables will satisfy my need with the functionality that you mentioned below.  I'll give it a shot and let you know if I run into any problems.

Thanks!

-Brian
Reply all
Reply to author
Forward
0 new messages