DataTable -- Add Sorting to Only One Column


I was wondering if it is possible to implement sorting for only one column in a dash DataTable. I’ve looked around the forums a bit and haven’t found any good answers confirming whether or not this functionality exists.

Currently, I set the sort_action attribute of my DataTable to ‘native’ which allows for sorting. However, I’d really only like to allow the user to be able to sort by the first three columns of the table. Is there a way to do this? From the docs it looks like I could potentially clobber something together whereby I use sort_action=‘custom’ and then implement a custom callback that simply ignores the sorting action if it was performed on a column I don’t want the user to be able to sort by. This seems messy and also wouldn’t remove the sorting UI elements on those columns, which could be confusing to a user.

Below is my current code for the app layout. current_matrix is just a Pandas dataframe I’m using to populate the table.

app.layout = html.Div([
            columns=[{'name': col, 'id': col} for col in current_matrix.columns],
            data = current_matrix.to_dict('records'),



I don’t think this is possible, although it would be an interesting feature to have. The solution you suggested seems to be the right way to go. You could style differently the sortable and non-sortable columns as explained here.

1 Like

+1. Don’t want to clutter up the interface (in this case, the header cell) for a column that has non-sortable data (for example, an image)

+1 on this feature ! A “sortable” attribute at the column level…?

+1 on this feature. I have a need for this right now. I have a column that has a string representation of risk, something like 3:(Range: 0-11). For values in this column that are less than one, the string representation is <1. Sorting the string representation is problematic. If I can’t turn sorting off, is there a way to sort that column by data values rather than column values?

Another +1, really need this and surprise sortable columns is an all-or-none.

One workaround may be to use dash-tabulator. Tabulator Dash Component

It doesn’t have all of the features of the Dash DataTable, but it does have some things that the Dash table does not have yet, such as specifying which columns are sortable. More info here:

For anyone who faced this problem, here is a workaround. Consider a table where we have two columns foo and bar, and we want only foo to be sortable.

table_columns  = [
        'id': 'foo',
        'name': 'Foo',
        'sortable': True,
        'id': 'bar',
        'name': 'Bar',
        'sortable': False,

non_sortable_column_ids = [col['id'] for col in table_columns if col.pop('sortable') is False]

table_css = [
        'selector': f'th[data-dash-column="{col}"] span.column-header--sort',
        'rule': 'display: none',
    for col in non_sortable_column_ids

table = dash_table.DataTable(

Hope it helps.


Yeah, it worked perfectly! :smiley: