Questions tagged [django-tables2]

django-tables2 simplifies the task of turning sets of data into HTML tables.

Native support for pagination and sorting. It does for HTML tables what django.forms does for HTML forms.

  • Any iterable can be a data-source, but special support for Django querysets is included.
  • The builtin UI does not rely on JavaScript.
  • Support for automatic table generation based on a Django model.
  • Supports custom column functionality via subclassing.
  • Pagination.
  • Column based table sorting.
  • Template tag to enable trivial rendering to HTML.
  • Generic view mixin.

Related links:

628 questions
5
votes
1 answer

How to change order_by dynamically using django-tables2?

My table class looks pretty typical except that maybe it includes a before_render() function. What's great about before_render is that I can access self. This gives me access to dynamic information about the model I'm using. How can I access dynamic…
Liam Hanninen
  • 1,525
  • 2
  • 19
  • 37
5
votes
1 answer

django-tables2/django-filter - pagination with filterclass

Good Afternoon, I am using a custom django-filter in django-tables2 to search all fields with a single input. Ive just noticed that when I search I lose my pagination menu. this is the link to the filter code…
AlexW
  • 2,843
  • 12
  • 74
  • 156
5
votes
3 answers

disable ordering by default for django_tables2 Tables

I use django_tables2 to render my tables. For one table, I only want to see the most recent 5 entries. Therefore, I need to order my queryset before passing it to the table object: qset = myObject.objects.order_by('-start_time').all()[:5] table =…
ezdazuzena
  • 6,120
  • 6
  • 41
  • 71
5
votes
5 answers

django tables how to detect if table is empty

I am new to django and web development and based on examples and help on SO, I have pieced together something which takes a model and renders it in a django-table. My template code is basically as follows: {% block content %} {% load static %} {%…
Luca
  • 10,458
  • 24
  • 107
  • 234
5
votes
2 answers

Django tables2 - how to sort table column on page loading?

I'm using django tables2 to render data in table form. I want the table to be sorted by column1 as default when page loading. The sort is working on clicking the column but I want this to be sorted by default on page loading.
5
votes
1 answer

How to change color of Django-tables row?

is it possible to change a color of row based on current object's value? In my case, I have a table created from model Job. The Job has attribute delivery. If job.delivery is for example 'delivered', I want to change the color of the row to red. The…
Milano
  • 18,048
  • 37
  • 153
  • 353
5
votes
1 answer

django: django-tables2 DetailView CBV won't display single object

I have a table import django_tables2 as tables from .models import Account from django_tables2.utils import A # alias for Accessor class AccountTable(tables.Table): nickname = tables.LinkColumn('accounts:detail', args=[A('pk')]) class…
mastachimp
  • 438
  • 3
  • 14
5
votes
2 answers

Django - Override data content of a django-tables2 LinkColumn

I use django-tables2 LinkColumn to create a column that call a function that allow the export of the object in the table. forms.py: class FilesTable(tables.Table): id = tables.LinkColumn('downloadFile', args=[A('pk')], verbose_name='Export') I…
Below the Radar
  • 7,321
  • 11
  • 63
  • 142
5
votes
1 answer

Accessing related models with django-tables2

Can anyone provide a clear example of how to create a table object using django-tables2 that selects and presents data from multiple related models (ie a relational join)? The documentation implies this is possible, but does not say how. In normal…
chill
  • 53
  • 1
  • 5
4
votes
2 answers

django-tables2 - accessing values of other columns in a table class

Let's assume I have the following table class: class TestTable(tables.Table): id = tables.Column() description = tables.Column() def render_description(self, value): return mark_safe('''%s''' % (???, value)) Is…
noplacetoh1de
  • 219
  • 3
  • 12
4
votes
2 answers

Using linkify option on Django_tables2 columns to create links

I want to add a link to my listview using linkify in the Columns of the API Reference. I am using Django 2 with Django_tables2 v 2.0.0b3 I have a URL with two context variables name, which is passed from the ListView and the slug field…
ccsv
  • 8,188
  • 12
  • 53
  • 97
4
votes
2 answers

Using Django tables 2, how do you cut off a long text field with an ellipsis?

I am using django-tables2 and I have a field that has really long text. Which I would like to truncate like this: It is a bootstrap table: class EntryRecordTable(tables.Table): ... comment = tables.Column(accessor=A('Comment')) class…
tread
  • 10,133
  • 17
  • 95
  • 170
4
votes
3 answers

How to format the display of floats when using django-tables2?

I am using django-tables2 to display some data. I have a column of floats and want them to be shown to just two decimal places (so, 10.238324 would be shown as 10.24). Is there a simple way to do this? In Django templates, I do this using…
cort
  • 89
  • 1
  • 9
4
votes
2 answers

How to use user permissions in django-tables2 Column

Using djang-tables2 custom table as: tables.py: import django_tables2 as tables from django_tables2.utils import A from .models import Person class PersonTable(tables.Table): view_column = tables.LinkColumn('person:pessoas_detail',…
4
votes
1 answer

many to many in django-tables2

I have django's models with many to many through ForeignKey: class A(m.Model): id = m.AutoField(primary_key=True) name = m.CharField(max_length=250, unique=True, null=False) def __str__(self): return…
1 2
3
41 42