Package: django4-2-datatable
online demoOverviewdjango-datatable is a simple Django app to organize data in tabular
form based ondatatableandbootstrap.It is worth mentioning that the design of this project makes reference
todjango-table2and is mainly for the purpose of learning. I really appreciate anyone
making a pull-request to improve it.RequirementsPython 2.xjQuery 1.6+Django 1.5+Bootstrap 3.0Quick startSetup Django-datatable application in Python environment:$ pip install django-datatableDefine a simple model named Person:# example/app/models.py
class Person(models.Model):
    name = models.CharField(max_length=100)Add “table” to your INSTALLED_APPS setting like this:INSTALLED_APPS = (
    ...,
    'table',
)Add some data so you have something to display in the table. Now
define a PersonTable class without any options in the table file.# example/app/tables.py
from models import Person
from table import Table
from table.columns import Column

class PersonTable(Table):
    id = Column(field='id')
    name = Column(field='name')
    class Meta:
        model = PersonAnd pass a table instance to the view.# example/app/views.py
from django.shortcuts import render
from app.tables import PersonTable

def people(request):
    people = PersonTable()
    return render(request, "index.html", {'people': people})Finally, implement the template:{# example/templates/index.html}
{% load static %}
{% load table_tags %}

<link href="{% static 'table/css/bootstrap.min.css' %}" rel="stylesheet">
<script src="{% static 'table/js/jquery.min.js' %}"></script>
<script src="{% static 'table/js/bootstrap.min.js' %}"></script>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>person</title>
    </head>
    <body>
        <div class="container" style="margin-top: 10px">
            <h1>people</h1>
            <br />
            {% render_table people %}
        </div>
    </body>
</html>TagRender the whole table by simple tag{% render_table %}, passTableinstance as single argument.{% render_table table %}DataSourceModelUses a django MTV model as table data source, and queries all data in
database by default. Seemodelin table options for details.QuerySetSimiliar toModel, but pass queryset when you initialize the table
instance instead of defining model option. Basically, it is used to
filter or sort data you want to display in table.Models:

    # models.py
    class Person(models.Model):
        name = models.CharField(max_length=100)

Tables:

    # tables.py
    from models import Person
    from table import Table
        from table.columns import Column

    class PersonTable(Table):
        id = Column(field='id')
        name = Column(field='name')

Views:

    # views.py
    from django.shortcuts import render
    from models import Person
    from app.tables import PersonTable

    def people(request):
        people = PersonTable(Person.objects.all())
        return render(request, "index.html", {'people': people})Dict-ListUse a list of dictionaries as table data source. Fields declared in
columns correspond to the dictionary keys.Tables:

    # tables.py
    from table import Table
    from table.columns import Column

    class PersonTable(Table):
        id = Column(field='id')
        name = Column(field='name')

Views:

    # views.py
    from django.shortcuts import render
    from app.tables import PersonTable

    def people(request):
        data = [{'id': 1, 'name': 'John'}, {'id': 2, 'name': 'Tom'}]
        people = PersonTable(data)
        return render(request, "index.html", {'people': people})Built-in AjaxFor large amounts of data, loading them on front-end entirely is
impossible. So, django-table provides a simle option ‘ajax’ to load data
from the server-side asynchronously.Note that once togglingajax, themodeloption is necessary.
Django-table will do paging/searching/sorting based onModelClass.objects.all().Urls:

    # urls.py
    urlpatterns = patterns('',
        url(r'^table/', include(table.urls')),
    )

Tables:

    # tables.py
    from table import Table
    from table.columns import Column

    class PersonTable(Table):
        id = Column(field='id')
        name = Column(field='name')

        class Meta:
            model = Person
            ajax = TrueCustom AjaxIf you want to customize base data, useajax_sourceoption and
implement your own Class-based View by subclassingFeedDataView.Tables:

    # tables.py
    class PersonTable(Table):
        id = Column(field='id')
        name = Column(field='name')

        class Meta:
            model = Person
            ajax = True
            ajax_source = reverse_lazy('table_data')

Urls:

    # urls.py
    urlpatterns = patterns('',
        url(r'^table/data/$', MyDataView.as_view(), name='table_data'),
    )

Views:

    # views.py
    from table.views import FeedDataView
    from app.tables import PersonTable

    class MyDataView(FeedDataView):

        token = PersonTable.token

        def get_queryset(self):
            return super(MyDataView, self).get_queryset().filter(id__gt=5)ColumnsColumnLink ColumnDatetime ColumnCheckbox ColumnSequence ColumnCalendar ColumnWidgetssearch-boxinfo-labelpaginationlength-menuexten-button(deprecated)API Referencewiki