Skip to content

Commit

Permalink
Add new example: ButtonTable.
Browse files Browse the repository at this point in the history
  • Loading branch information
shymonk committed May 11, 2017
1 parent 7181ca0 commit b0df2e6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@
## v0.1.0

First commit for codebase.

## v0.11.0

* Deprecate table option `ext_button`.
* Make table template inheritable.
45 changes: 27 additions & 18 deletions example/app/tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# coding: utf-8

from datetime import date
import django

Expand All @@ -22,26 +21,26 @@


class ModelTable(Table):
id = Column(field='id', header=u'#')
name = Column(field='name', header=u'NAME')
id = Column(field='id', header='#')
name = Column(field='name', header='NAME')

class Meta:
model = Person


class AjaxTable(Table):
id = Column(field='id', header=u'#')
name = Column(field='name', header=u'NAME')
organization = Column(field='organization.name', header=u'ORG')
id = Column(field='id', header='#')
name = Column(field='name', header='NAME')
organization = Column(field='organization.name', header='ORG')

class Meta:
model = Person
ajax = True


class AjaxSourceTable(Table):
id = Column(field='id', header=u'#')
name = Column(field='name', header=u'NAME')
id = Column(field='id', header='#')
name = Column(field='name', header='NAME')

class Meta:
model = Person
Expand All @@ -50,35 +49,45 @@ class Meta:


class SequenceColumnTable(Table):
id = Column(field='id', header=u'#')
id = Column(field='id', header='#')
seq = SequenceColumn(field='calendar', headers=["A", "B", "C", "D", "E"])


class CalendarColumnTable(Table):
id = Column(field='id', header=u'#', header_attrs={'rowspan': '3'})
name = Column(field='name', header=u'NAME', header_attrs={'rowspan': '3'})
id = Column(field='id', header='#', header_attrs={'rowspan': '3'})
name = Column(field='name', header='NAME', header_attrs={'rowspan': '3'})
calendar = CalendarColumn(field='calendar', start_date=date(2014, 4, 27), end_date=date(2014, 5, 9))


image_url = 'https://cdn0.iconfinder.com/data/icons/users-android-l-lollipop-icon-pack/24/user-32.png'


class LinkColumnTable(Table):
id = Column(field='id', header=u'#')
name = LinkColumn(header=u'NAME', links=[
id = Column(field='id', header='#')
name = LinkColumn(header='NAME', links=[
Link(viewname='user_profile', args=(A('id'),), text=A('name'))])
avatar = LinkColumn(header=u'AVATAR', links=[
avatar = LinkColumn(header='AVATAR', links=[
ImageLink(viewname='user_profile', args=(A('id'),), image=image_url, image_title='avatar')])
# logo = ImageColumn(field='logo.url', header=u'Logo Image', image_title='logo')
# logo = ImageColumn(field='logo.url', header='Logo Image', image_title='logo')

class Meta:
model = Person


class CheckboxColumnTable(Table):
id = Column(field='id', header=u'#')
name = Column(field='name', header=u'NAME')
married = CheckboxColumn(field='married', header=u'MARRIED')
id = Column(field='id', header='#')
name = Column(field='name', header='NAME')
married = CheckboxColumn(field='married', header='MARRIED')

class Meta:
model = Person


class ButtonsExtensionTable(Table):
id = Column(field='id', header='#')
name = Column(field='name', header='NAME')
organization = Column(field='organization.name', header='ORGANIZATION')

class Meta:
model = Person
template_name = 'buttons_table.html'
7 changes: 6 additions & 1 deletion example/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from app.tables import (
ModelTable, AjaxTable, AjaxSourceTable,
CalendarColumnTable, SequenceColumnTable,
LinkColumnTable, CheckboxColumnTable
LinkColumnTable, CheckboxColumnTable,
ButtonsExtensionTable
)


Expand Down Expand Up @@ -64,6 +65,10 @@ def checkbox_column(request):
return render(request, "index.html", {'people': table})


def buttons_extension(request):
table = ButtonsExtensionTable()
return render(request, "index.html", {'people': table})

def user_profile(request, uid):
from app.models import Person
from django.http import HttpResponse
Expand Down
21 changes: 21 additions & 0 deletions example/templates/buttons_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "table/table.html" %}

{% block extra_css %}
<link href="//cdn.datatables.net/buttons/1.3.1/css/buttons.bootstrap.min.css" rel="stylesheet" media="screen">
{% endblock extra_css %}

{% block extra_js %}
<script src="//cdn.datatables.net/buttons/1.3.1/js/dataTables.buttons.min.js" type="text/javascript"></script>
<script src="//cdn.datatables.net/buttons/1.3.1/js/buttons.bootstrap.min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js" type="text/javascript"></script>
<script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js" type="text/javascript"></script>
<script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/vfs_fonts.js" type="text/javascript"></script>
<script src="//cdn.datatables.net/buttons/1.3.1/js/buttons.html5.min.js" type="text/javascript"></script>
{% endblock extra_js %}

{% block table_dom %}
"dom": "<'row'<'col-sm-9 col-md-9 col-lg-9'B><'col-sm-3 col-md-3 col-lg-3'f>>rt<'row'<'col-sm-3 col-md-3 col-lg-3'i><'col-sm-6 col-md-6 col-lg-6 col-sm-offset-2 col-md-offset-2 col-lg-offset-2'p><'col-sm-1 col-md-1 col-lg-1'l>>",
{% endblock %}
{% block table_extra_options %}
"buttons": ['copy', 'excel', 'pdf'],
{% endblock %}
14 changes: 10 additions & 4 deletions example/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>person</title>

<link rel="stylesheet" href="http://cdn.bootcss.com/twitter-bootstrap/3.0.2/css/bootstrap.min.css">
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/twitter-bootstrap/3.0.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//cdn.bootcss.com/twitter-bootstrap/3.0.2/css/bootstrap.min.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//cdn.bootcss.com/twitter-bootstrap/3.0.2/js/bootstrap.min.js"></script>
</head>

<body>
Expand All @@ -18,7 +18,7 @@
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed"></button>
<a class="navbar-brand" href="/">django-datatable</a>
<a class="navbar-brand" href="/" style="font-size:21px;color:#fff;font-weight:500;">django-datatable</a>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
Expand All @@ -45,6 +45,12 @@
<li><a href="/column/checkbox/">Checkbox Column</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Extensions</a>
<ul class="dropdown-menu" role="menu">
<li><a href="/extensions/buttons/">Buttons</a></li>
</ul>
</li>
</ul>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
url(r'^column/link/$', app.views.link_column, name='link_column'),
url(r'^column/checkbox/$', app.views.checkbox_column, name='checkbox_column'),

url(r'^extensions/buttons/$', app.views.buttons_extension, name='buttons_extension'),

url(r'^user/(\d+)/$', app.views.user_profile, name='user_profile'),
url(r'^table/', include('table.urls')),
]

0 comments on commit b0df2e6

Please sign in to comment.