jieter / django-tables2

django-tables2 - An app for creating HTML tables
https://django-tables2.readthedocs.io/en/latest/
Other
1.86k stars 426 forks source link

Disable User-sortable Columns #911

Closed jmoppel closed 2 months ago

jmoppel commented 1 year ago

Hello, thanks for the terrific library. It has worked great with Bootstrap Table! Is there a way to remove the end user's ability to sort columns by clicking on column headers (i.e., de-linkify the column headers), while still being able to sort the columns in the Table class and via URL parameters?

The goal is to sort the table by a default field (e.g., name) and then hand the HTML off to Bootstrap Table, for the more dynamic things. I've looked around the documentation a fair bit, but nothing stated it ignored orderable (which turns off sorting everywhere, it seems). It looks like turning off clickable headers using the Column API might be possible. However, it was a bit difficult to make out how to go about it (assuming this is the right track at all) since there weren't any examples that I could find in the Columns section. I would be grateful for guidance on the best way to solve this problem. Thanks again!

Alexandre-petitjean commented 6 months ago

You can disable this in the init of your custom Column

class PictureColumn(tables.Column):

    def __init__(self, *args, **kargs):
        super().__init__(*args, **kargs)
        self.orderable = False

Or you can pass the arg to the column in the table definition.

class ConsumableTable(tables.Table):
    picture = PictureColumn(accessor="get_picture_url", orderable=False)
jieter commented 2 months ago

This is an issue tracker to report bugs and request features, not a place to ask for help on using the library. Please use stackoverflow and tag your question with django-tables2