{"id":15063514,"url":"https://github.com/djk2/django-tables2-column-shifter","last_synced_at":"2025-09-07T21:45:55.510Z","repository":{"id":50941428,"uuid":"74339709","full_name":"djk2/django-tables2-column-shifter","owner":"djk2","description":"Simple extension for django-tables2 can dynamically show or hide columns. Using JQuery, Bootstrap 3, Bootstrap 4, Bootstrap 5 and Django \u003e=1.9","archived":false,"fork":false,"pushed_at":"2023-05-03T09:00:44.000Z","size":1301,"stargazers_count":22,"open_issues_count":1,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-08T13:17:08.469Z","etag":null,"topics":["bootstrap3","bootstrap4","bootstrap5","column","django","django-tables2"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/djk2.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-21T07:57:17.000Z","updated_at":"2025-02-24T00:45:07.000Z","dependencies_parsed_at":"2024-06-20T00:09:35.702Z","dependency_job_id":"7ba2f859-0899-4585-ae36-a34215bf13a3","html_url":"https://github.com/djk2/django-tables2-column-shifter","commit_stats":{"total_commits":61,"total_committers":6,"mean_commits":"10.166666666666666","dds":0.5901639344262295,"last_synced_commit":"90695d5890c4ef6d7ba58a189a53d712aa8b9e14"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djk2%2Fdjango-tables2-column-shifter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djk2%2Fdjango-tables2-column-shifter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djk2%2Fdjango-tables2-column-shifter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djk2%2Fdjango-tables2-column-shifter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djk2","download_url":"https://codeload.github.com/djk2/django-tables2-column-shifter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208561,"owners_count":21065202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bootstrap3","bootstrap4","bootstrap5","column","django","django-tables2"],"created_at":"2024-09-25T00:03:36.170Z","updated_at":"2025-04-10T11:11:33.744Z","avatar_url":"https://github.com/djk2.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"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 \u003e=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 bootstrap4 in responsive mode - ColumnShiftTableBootstrap4Responsive (only for django-tables2 \u003e= 2.5)\n  * for bootstrap5 - ColumnShiftTableBootstrap5\n  * for bootstrap5 in responsive mode - ColumnShiftTableBootstrap5Responsive (only for django-tables2 \u003e= 2.5.3)\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 \u003e= 1.9\n* django-tables2 \u003e= 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 \u003c/body\u003e 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    \u003cbody\u003e\n        ...\n        ...\n        \u003cscript src=\"{% static \"jquery.min.js\" %}\"\u003e\u003c/script\u003e {# require #}\n        {# Popper is a dependency for bootstrap \u003e= 4.0 #}\n        \u003cscript src=\"{% static \"bootstrap/js/popper.min.js\" %}\"\u003e\u003c/script\u003e\n        \u003cscript src=\"{% static \"bootstrap/js/bootstrap.min.js\" %}\"\u003e\u003c/script\u003e\n\n        \u003cscript\n            type=\"text/javascript\"\n            src=\"{% static \"django_tables2_column_shifter/js/django_tables2_column_shifter.min.js\" %}\"\u003e\n        \u003c/script\u003e\n    \u003c/body\u003e\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 ``\u0026excluded_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\nAlternatively if you want to use `table-responsive` your table class has to inherit from\nColumnShiftTableBootstrap4Responsive (only for django-tables2 \u003e= 2.5).\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\nAlternatively if you want to use `table-responsive` your table class has to inherit from\nColumnShiftTableBootstrap5Responsive (only for django-tables2 \u003e= 2.5.3).\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 \u003chttps://docs.djangoproject.com/en/dev/\u003e`_\n- `django-tables2 documentation \u003chttps://django-tables2.readthedocs.io/en/latest/\u003e`_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjk2%2Fdjango-tables2-column-shifter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjk2%2Fdjango-tables2-column-shifter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjk2%2Fdjango-tables2-column-shifter/lists"}