@qu3st wrote:
Hello,
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([ html.Div([ dash_table.DataTable( id='displayed-matrix', columns=[{'name': col, 'id': col} for col in current_matrix.columns], data = current_matrix.to_dict('records'), sort_action='native' ) ]) ])
Thanks!
Posts: 2
Participants: 2