Live demo

ID headline blog pub date


Description

Columns that should be blocked from sorting (on the frontend and also by the backend) can be enumerated in the datatable_options['unsortable_columns'] key.

When the table structure is initially rendered onto the page, the <th> elements are given attributes in a data-* API fashion. (dataTables.js does not actually support this API, but it greatly simplifies the legwork required to get a table automatically initialized.) For sorting, the data attribute is data-sortable, the value being "true" by default, but "false" if the column name is given in the unsortable columns list.



Implementation in code

        
    class UnsortableColumnsDatatableView(DatatableView):
        model = Entry
        datatable_options = {
            'columns': [
                'id',
                'headline',
                'body_text',
                'blog',
                'pub_date',
            ],
            'unsortable_columns': ['headline', 'body_text', 'blog', 'pub_date'],
        }