django-tables2-column-shifter
------------------------------
.. image:: https://badge.fury.io/py/django-tables2-column-shifter.svg
:target: https://badge.fury.io/py/django-tables2-column-shifter
:alt: Latest PyPI version
.. image:: https://github.com/djk2/django-tables2-column-shifter/actions/workflows/tests.yaml/badge.svg?branch=master
:target: https://github.com/djk2/django-tables2-column-shifter/actions/workflows/tests.yaml
:alt: GitHub Actions
.. image:: https://requires.io/github/djk2/django-tables2-column-shifter/requirements.svg?branch=master
:target: https://requires.io/github/djk2/django-tables2-column-shifter/requirements/?branch=master
:alt: Requirements Status
**About the app:**
Simple extension for django-tables2 to dynamically show or hide columns using jQuery.
Application uses web storage to store information whih columns are visible or not.
Using JQuery, Bootstrap3 or Bootstrap4 or Bootstrap5 and Django >=1.9.
**Warning** : - Since version 2.0 my extension works by default with bootstrap4.
I highly recommend to inherit explicite from tables class indicate on bootstrap version.
I.e if you use in your project bootstrap in version 5.
Your `Table` classes should inherit from:
`django_tables2_column_shifter.tables.ColumnShiftTableBootstrap5`.
Now you should inherit from:
* for bootstrap2 - ColumnShiftTableBootstrap2,
* for bootstrap3 - ColumnShiftTableBootstrap3,
* for bootstrap4 - ColumnShiftTableBootstrap4,
* for bootstrap5 - ColumnShiftTableBootstrap5,
**Tested by tox with:**
* Python :3.6, 3.8, 3.10
* Django : 1.9, 1.10, 1.11, 2.0, 2.1, 3.0, 3.1, 3.2, 4.0, 4.2, master
* django-tables2 : 1.15, ..., 1.21, 2.0, 2.1, 2.2, 2.3, 2.5, master
**Supported:**
* Django >= 1.9
* django-tables2 >= 1.15 (earlier version probably will work but wasn't tested)
* **bootstrap2** / **bootstrap3** / **bootstrap4** / **bootstrap4.1.3** / **bootstrap5 beta3**
* **JQuery**
**Supported locale:**
* EN - (English)
* PL - (Polish)
* EL - (Greek / Hellenic Republic)
* PT-BR - (Portuguese - Brazilian)
More information about django-tables in here: https://django-tables2.readthedocs.io/
Screens:
----------
.. image:: https://raw.githubusercontent.com/djk2/django-tables2-column-shifter/master/doc/static/scr1.png
:alt: screen 1
.. image:: https://raw.githubusercontent.com/djk2/django-tables2-column-shifter/master/doc/static/scr2.png
:alt: screen 2
How to Install:
---------------
1. Install django-tables2-column-shifter using::
pip install django-tables2-column-shifter
or
pip install git+https://github.com/djk2/django-tables2-column-shifter
or
pip install django-tables2-column-shifter.zip
or
pip install django-tables2-column-shifter.tar.gz
2. Add ``django_tables2_column_shifter`` to your ``INSTALLED_APPS`` setting (after django_tables2) like this ::
INSTALLED_APPS = [
...,
'django_tables2',
'django_tables2_column_shifter',
...,
]
3. Add path to js script: ``django_tables2_column_shifter.min.js`` in your base django template.
Script must be add after jquery.js and bootstrap.js and before </body> tag.
Draw attention to fact that beginning from version 4 of bootstrap,
the `Popper.js` is required to proper work of some of JS bootstrap scripts.
More about dependencies here:
https://getbootstrap.com/docs/4.0/getting-started/javascript/#dependencies
base.html::
{% load static %}
<body>
...
...
<script src="{% static "jquery.min.js" %}"></script> {# require #}
{# Popper is a dependency for bootstrap >= 4.0 #}
<script src="{% static "bootstrap/js/popper.min.js" %}"></script>
<script src="{% static "bootstrap/js/bootstrap.min.js" %}"></script>
<script
type="text/javascript"
src="{% static "django_tables2_column_shifter/js/django_tables2_column_shifter.min.js" %}">
</script>
</body>
Usage:
------
To use app, you must inherit your table class from ``django_tables2_column_shifter.tables.ColumnShiftTable``
models.py - create ordinary model::
from django.db import models
class MyModel(models.Model):
first_name = models.CharField("First name", max_length=50)
last_name = models.CharField("Last name", max_length=50)
tables.py - change inherit to one of: ColumnShiftTableBootstrap2,
ColumnShiftTableBootstrap3, ColumnShiftTableBootstrap4, ColumnShiftTableBootstrap5
(depends on which bootstrap version of bootstrap you are using)::
from django_tables2_column_shifter.tables import (
ColumnShiftTableBootstrap2, # If you use bootstrap2
ColumnShiftTableBootstrap3, # If you use bootstrap3
ColumnShiftTableBootstrap4, # If you use bootstrap4
ColumnShiftTableBootstrap5, # If you use bootstrap5
)
from app.models import MyModel
# By default you probably inherit from django_table2.Table
# Change inherit to ColumnShiftTableBootstrap4
# if you use bootstrap4
class MyModelTable(ColumnShiftTableBootstrap4):
class Meta:
model = MyModel
# or if you use bootstrap5
class MyModelTable(ColumnShiftTableBootstrap5):
class Meta:
model = MyModel
views.py - In your view, nothing changes::
from .tables import MyModelTable
from .models import MyModel
def simple_list(request):
queryset = MyModel.objects.all()
table = MyModelTable(queryset)
return render(request, 'template.html', {'table': table})
template.html - use default render_table tag to display table object (using bootstrap3 / bootstrap4 / bootstrap5)::
{% extends "base.html" %}
{% load django_tables2 %}
{% render_table table %}
JS API:
-------
This library is initialized automatically on the page ready event. In case you are using a framework
like htmx, unpoly or turbo that does not trigger the ready event, you can initialize it manually by calling
``$.django_tables2_column_shifter_init()`` on your framework's initialize callback.
To retrieve the invisible columns you can use the ``$.django_tables2_column_shifter_hidden()`` js API.
You can either pass the 0-based index of the table in the page (i.e use ``$.django_tables2_column_shifter_hidden(1)``
to get the hidden columns for the 2nd table in the page) or just use it without parameters to retrieve the hidden columns
for the first table. This API returns an array with the invisible column names.
These columns can then be used when you want to export only the visible columns,
ie when the user clicks on the export button it would append an ``&excluded_columns=col1,col2``
to the export button's ``href`` which would then be used by the django-tables2 ``TableExporter``
(http://django-tables2.readthedocs.io/en/latest/pages/export.html#excluding-columns) to exclude
these cols, i.e something like
exporter = TableExport('csv', table, exclude_columns=self.request.GET.get('excluded_columns').split(',))
Bootstrap2 (support for old projects):
--------------------------------------
If you use Bootstrap v2 in your project then table class has to inherit from `ColumnShiftTableBootstrap2`
imported from `django_tables2_column_shifter.tables`.
Bootstrap3 (support for old projects):
--------------------------------------
If you use Bootstrap v3 in your project then table class has to inherit from `ColumnShiftTableBootstrap3`
imported from `django_tables2_column_shifter.tables`.
Bootstrap4 :
--------------------------------------
If you use Bootstrap v4 in your project then table class has to inherit from `ColumnShiftTableBootstrap4`
imported from `django_tables2_column_shifter.tables`.
Bootstrap5:
--------------------------------------
If you use Bootstrap v5 in your project then table class has to inherit from `ColumnShiftTableBootstrap5`
imported from `django_tables2_column_shifter.tables`.
Warnings:
----------
- **Warning** : - If you use {% render_table %} tag with queryset (not table class instance),
django-tables2-column-shifter will not be work. Queryset does not have ``template`` attribute::
{% load django_tables2 %}
{% render_table queryset %} {# not work #}
- **Warning** : - If you use a different template than ``django_tables2_column_shifter/bootstrap*.html``
to render your table, probably django-tables2-column-shifter will not be work.
Your custom template should inherit from ``django_tables2_column_shifter/bootstrap*.html``
- **Warning** : - Since version 2.0 the default template is not used for Table class.
Moreover template ``django_tables2_column_shifter/table.html`` by default inherit from
``django_tables2_column_shifter/bootstrap4.html``
Customizing:
-------------
1. If you use more then one instance of the same Table class, you should use a different prefix for each instance::
tab1 = MyModelTable(queryset, prefix='tab1')
tab2 = MyModelTable(queryset, prefix='tab2')
tab3 = MyModelTable(queryset, prefix='tab3')
2. To disable shifter mechanism - set ``False`` to ``shift_table_column`` in your table class (default value is True)::
class MyModelTable(ColumnShiftTableBootstrap5):
shift_table_column = False
...
3. By default, all columns from sequence are visible, if you want limit visible columns,
override method ``get_column_default_show(self)`` like that::
class MyModelTable(ColumnShiftTableBootstrap5):
def get_column_default_show(self):
self.column_default_show = ['column1', 'column2']
return super(MyModelTable, self).get_column_default_show()
4. By default, all columns from sequence are visible, if you want exclude some colmumns and
block ability to manipulate then, use: ``column_excluded``
class MyModelTable(ColumnShiftTableBootstrap5):
column_excluded = ['ex_column1', 'ex_column2']
or
class MyModelTable(ColumnShiftTableBootstrap5):
def get_column_excluded(self):
self.column_excluded = ['ex_column1', 'ex_column2']
return super(MyModelTable, self).get_column_excluded()
Run demo:
---------
1. Download or clone project from `https://github.com/djk2/django-tables2-column-shifter`::
git clone https://github.com/djk2/django-tables2-column-shifter.git
2. Go to testproject directory::
cd django-tables2-column-shifter/testproject
3. Install requirements::
pip install -r requirements.txt
4. Run django developing server::
python manage.py runserver
Links:
--------
- `Django documentation <https://docs.djangoproject.com/en/dev/>`_
- `django-tables2 documentation <https://django-tables2.readthedocs.io/en/latest/>`_
Raw data
{
"_id": null,
"home_page": "https://github.com/djk2/django-tables2-column-shifter",
"name": "django-tables2-column-shifter",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "django_tables2 django columns",
"author": "Grzegorz T\u0119\u017cycki",
"author_email": "grzegorz.tezycki@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/03/f8/31f9341839f15ab8198852cd682f4fde08b6a4aad0e15a5890d0c4c6958f/django-tables2-column-shifter-2.1.1.tar.gz",
"platform": null,
"description": "django-tables2-column-shifter\n------------------------------\n\n\n.. image:: https://badge.fury.io/py/django-tables2-column-shifter.svg\n :target: https://badge.fury.io/py/django-tables2-column-shifter\n :alt: Latest PyPI version\n\n\n.. image:: https://github.com/djk2/django-tables2-column-shifter/actions/workflows/tests.yaml/badge.svg?branch=master\n :target: https://github.com/djk2/django-tables2-column-shifter/actions/workflows/tests.yaml\n :alt: GitHub Actions\n\n\n.. image:: https://requires.io/github/djk2/django-tables2-column-shifter/requirements.svg?branch=master\n :target: https://requires.io/github/djk2/django-tables2-column-shifter/requirements/?branch=master\n :alt: Requirements Status\n\n\n**About the app:**\nSimple extension for django-tables2 to dynamically show or hide columns using jQuery.\nApplication uses web storage to store information whih columns are visible or not.\nUsing JQuery, Bootstrap3 or Bootstrap4 or Bootstrap5 and Django >=1.9.\n\n\n**Warning** : - Since version 2.0 my extension works by default with bootstrap4.\n I highly recommend to inherit explicite from tables class indicate on bootstrap version.\n I.e if you use in your project bootstrap in version 5.\n Your `Table` classes should inherit from:\n `django_tables2_column_shifter.tables.ColumnShiftTableBootstrap5`.\n\n Now you should inherit from:\n\n * for bootstrap2 - ColumnShiftTableBootstrap2,\n * for bootstrap3 - ColumnShiftTableBootstrap3,\n * for bootstrap4 - ColumnShiftTableBootstrap4,\n * for bootstrap5 - ColumnShiftTableBootstrap5,\n\n**Tested by tox with:**\n\n* Python :3.6, 3.8, 3.10\n* Django : 1.9, 1.10, 1.11, 2.0, 2.1, 3.0, 3.1, 3.2, 4.0, 4.2, master\n* django-tables2 : 1.15, ..., 1.21, 2.0, 2.1, 2.2, 2.3, 2.5, master\n\n**Supported:**\n\n* Django >= 1.9\n* django-tables2 >= 1.15 (earlier version probably will work but wasn't tested)\n* **bootstrap2** / **bootstrap3** / **bootstrap4** / **bootstrap4.1.3** / **bootstrap5 beta3**\n* **JQuery**\n\n**Supported locale:**\n\n* EN - (English)\n* PL - (Polish)\n* EL - (Greek / Hellenic Republic)\n* PT-BR - (Portuguese - Brazilian)\n\n\nMore information about django-tables in here: https://django-tables2.readthedocs.io/\n\n\nScreens:\n----------\n\n.. image:: https://raw.githubusercontent.com/djk2/django-tables2-column-shifter/master/doc/static/scr1.png\n :alt: screen 1\n\n.. image:: https://raw.githubusercontent.com/djk2/django-tables2-column-shifter/master/doc/static/scr2.png\n :alt: screen 2\n\n\nHow to Install:\n---------------\n1. Install django-tables2-column-shifter using::\n\n\n pip install django-tables2-column-shifter\n\n or\n\n pip install git+https://github.com/djk2/django-tables2-column-shifter\n\n or\n\n pip install django-tables2-column-shifter.zip\n\n or\n\n pip install django-tables2-column-shifter.tar.gz\n\n\n2. Add ``django_tables2_column_shifter`` to your ``INSTALLED_APPS`` setting (after django_tables2) like this ::\n\n INSTALLED_APPS = [\n ...,\n 'django_tables2',\n 'django_tables2_column_shifter',\n ...,\n ]\n\n3. Add path to js script: ``django_tables2_column_shifter.min.js`` in your base django template.\n Script must be add after jquery.js and bootstrap.js and before </body> tag.\n Draw attention to fact that beginning from version 4 of bootstrap,\n the `Popper.js` is required to proper work of some of JS bootstrap scripts.\n More about dependencies here:\n https://getbootstrap.com/docs/4.0/getting-started/javascript/#dependencies\n\n\n base.html::\n\n {% load static %}\n\n <body>\n ...\n ...\n <script src=\"{% static \"jquery.min.js\" %}\"></script> {# require #}\n {# Popper is a dependency for bootstrap >= 4.0 #}\n <script src=\"{% static \"bootstrap/js/popper.min.js\" %}\"></script>\n <script src=\"{% static \"bootstrap/js/bootstrap.min.js\" %}\"></script>\n\n <script\n type=\"text/javascript\"\n src=\"{% static \"django_tables2_column_shifter/js/django_tables2_column_shifter.min.js\" %}\">\n </script>\n </body>\n\n\nUsage:\n------\nTo use app, you must inherit your table class from ``django_tables2_column_shifter.tables.ColumnShiftTable``\n\n models.py - create ordinary model::\n\n from django.db import models\n\n class MyModel(models.Model):\n first_name = models.CharField(\"First name\", max_length=50)\n last_name = models.CharField(\"Last name\", max_length=50)\n\n tables.py - change inherit to one of: ColumnShiftTableBootstrap2,\n ColumnShiftTableBootstrap3, ColumnShiftTableBootstrap4, ColumnShiftTableBootstrap5\n (depends on which bootstrap version of bootstrap you are using)::\n\n from django_tables2_column_shifter.tables import (\n ColumnShiftTableBootstrap2, # If you use bootstrap2\n ColumnShiftTableBootstrap3, # If you use bootstrap3\n ColumnShiftTableBootstrap4, # If you use bootstrap4\n ColumnShiftTableBootstrap5, # If you use bootstrap5\n )\n from app.models import MyModel\n\n # By default you probably inherit from django_table2.Table\n # Change inherit to ColumnShiftTableBootstrap4\n # if you use bootstrap4\n class MyModelTable(ColumnShiftTableBootstrap4):\n class Meta:\n model = MyModel\n\n # or if you use bootstrap5\n class MyModelTable(ColumnShiftTableBootstrap5):\n class Meta:\n model = MyModel\n\n\n views.py - In your view, nothing changes::\n\n from .tables import MyModelTable\n from .models import MyModel\n\n def simple_list(request):\n queryset = MyModel.objects.all()\n table = MyModelTable(queryset)\n return render(request, 'template.html', {'table': table})\n\n template.html - use default render_table tag to display table object (using bootstrap3 / bootstrap4 / bootstrap5)::\n\n {% extends \"base.html\" %}\n {% load django_tables2 %}\n {% render_table table %}\n\n\n\nJS API:\n-------\n\nThis library is initialized automatically on the page ready event. In case you are using a framework\nlike htmx, unpoly or turbo that does not trigger the ready event, you can initialize it manually by calling\n``$.django_tables2_column_shifter_init()`` on your framework's initialize callback.\n\nTo retrieve the invisible columns you can use the ``$.django_tables2_column_shifter_hidden()`` js API.\nYou can either pass the 0-based index of the table in the page (i.e use ``$.django_tables2_column_shifter_hidden(1)``\nto get the hidden columns for the 2nd table in the page) or just use it without parameters to retrieve the hidden columns\nfor the first table. This API returns an array with the invisible column names.\n\nThese columns can then be used when you want to export only the visible columns,\nie when the user clicks on the export button it would append an ``&excluded_columns=col1,col2``\nto the export button's ``href`` which would then be used by the django-tables2 ``TableExporter``\n(http://django-tables2.readthedocs.io/en/latest/pages/export.html#excluding-columns) to exclude\nthese cols, i.e something like\n\n exporter = TableExport('csv', table, exclude_columns=self.request.GET.get('excluded_columns').split(',))\n\n\n\nBootstrap2 (support for old projects):\n--------------------------------------\nIf you use Bootstrap v2 in your project then table class has to inherit from `ColumnShiftTableBootstrap2`\nimported from `django_tables2_column_shifter.tables`.\n\nBootstrap3 (support for old projects):\n--------------------------------------\nIf you use Bootstrap v3 in your project then table class has to inherit from `ColumnShiftTableBootstrap3`\nimported from `django_tables2_column_shifter.tables`.\n\nBootstrap4 :\n--------------------------------------\nIf you use Bootstrap v4 in your project then table class has to inherit from `ColumnShiftTableBootstrap4`\nimported from `django_tables2_column_shifter.tables`.\n\nBootstrap5:\n--------------------------------------\nIf you use Bootstrap v5 in your project then table class has to inherit from `ColumnShiftTableBootstrap5`\nimported from `django_tables2_column_shifter.tables`.\n\n\n\nWarnings:\n----------\n\n- **Warning** : - If you use {% render_table %} tag with queryset (not table class instance),\n django-tables2-column-shifter will not be work. Queryset does not have ``template`` attribute::\n\n {% load django_tables2 %}\n {% render_table queryset %} {# not work #}\n\n\n- **Warning** : - If you use a different template than ``django_tables2_column_shifter/bootstrap*.html``\n to render your table, probably django-tables2-column-shifter will not be work.\n Your custom template should inherit from ``django_tables2_column_shifter/bootstrap*.html``\n\n- **Warning** : - Since version 2.0 the default template is not used for Table class.\n Moreover template ``django_tables2_column_shifter/table.html`` by default inherit from\n ``django_tables2_column_shifter/bootstrap4.html``\n\n\n\n\nCustomizing:\n-------------\n1. If you use more then one instance of the same Table class, you should use a different prefix for each instance::\n\n tab1 = MyModelTable(queryset, prefix='tab1')\n tab2 = MyModelTable(queryset, prefix='tab2')\n tab3 = MyModelTable(queryset, prefix='tab3')\n\n2. To disable shifter mechanism - set ``False`` to ``shift_table_column`` in your table class (default value is True)::\n\n class MyModelTable(ColumnShiftTableBootstrap5):\n shift_table_column = False\n ...\n\n\n3. By default, all columns from sequence are visible, if you want limit visible columns,\n override method ``get_column_default_show(self)`` like that::\n\n class MyModelTable(ColumnShiftTableBootstrap5):\n def get_column_default_show(self):\n self.column_default_show = ['column1', 'column2']\n return super(MyModelTable, self).get_column_default_show()\n\n4. By default, all columns from sequence are visible, if you want exclude some colmumns and\n block ability to manipulate then, use: ``column_excluded``\n\n class MyModelTable(ColumnShiftTableBootstrap5):\n column_excluded = ['ex_column1', 'ex_column2']\n\n or\n\n class MyModelTable(ColumnShiftTableBootstrap5):\n def get_column_excluded(self):\n self.column_excluded = ['ex_column1', 'ex_column2']\n return super(MyModelTable, self).get_column_excluded()\n\n\nRun demo:\n---------\n1. Download or clone project from `https://github.com/djk2/django-tables2-column-shifter`::\n\n git clone https://github.com/djk2/django-tables2-column-shifter.git\n\n2. Go to testproject directory::\n\n cd django-tables2-column-shifter/testproject\n\n3. Install requirements::\n\n pip install -r requirements.txt\n\n4. Run django developing server::\n\n python manage.py runserver\n\n\nLinks:\n--------\n- `Django documentation <https://docs.djangoproject.com/en/dev/>`_\n- `django-tables2 documentation <https://django-tables2.readthedocs.io/en/latest/>`_\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Extension for django_tables2 can dynamically show or hide columns",
"version": "2.1.1",
"split_keywords": [
"django_tables2",
"django",
"columns"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1301d2f966b080b99685bc70aeb5b67f1112339796aa81d67029f1997e10a11b",
"md5": "49894f0c317cd1aba490e0ef00ab25aa",
"sha256": "6135a20956235f32d8bf951520a985f6817508909746b9e08ca9e9a9fad6c3e2"
},
"downloads": -1,
"filename": "django_tables2_column_shifter-2.1.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "49894f0c317cd1aba490e0ef00ab25aa",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 27886,
"upload_time": "2023-04-07T07:22:58",
"upload_time_iso_8601": "2023-04-07T07:22:58.015162Z",
"url": "https://files.pythonhosted.org/packages/13/01/d2f966b080b99685bc70aeb5b67f1112339796aa81d67029f1997e10a11b/django_tables2_column_shifter-2.1.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "03f831f9341839f15ab8198852cd682f4fde08b6a4aad0e15a5890d0c4c6958f",
"md5": "8e27c10fc826f24c316b53233d120ecf",
"sha256": "4118bd350b02e27add7104197fcc1b743bbeea9dd96aece5c3708aaf18d99fca"
},
"downloads": -1,
"filename": "django-tables2-column-shifter-2.1.1.tar.gz",
"has_sig": false,
"md5_digest": "8e27c10fc826f24c316b53233d120ecf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 21936,
"upload_time": "2023-04-07T07:23:00",
"upload_time_iso_8601": "2023-04-07T07:23:00.328314Z",
"url": "https://files.pythonhosted.org/packages/03/f8/31f9341839f15ab8198852cd682f4fde08b6a4aad0e15a5890d0c4c6958f/django-tables2-column-shifter-2.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-07 07:23:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "djk2",
"github_project": "django-tables2-column-shifter",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-tables2-column-shifter"
}