Black Lives Matter. Please consider donating to Black Girls Code today.

Columns order in mutable Datatable?

Hi Chris,

Looking at your comment on the following link (see below), I noticed that the column order was random and that it can be controlled by the ‘columns’ argument.

However, assuming the Datatable is mutable, meaning that it’s column number and names depends on some input (In other words, depending on some inputs, the data my Datatable shows varies), Is there a way to update the ‘columns’ argument to take into account this situation or any other way to control the column order? other than the initial ‘columns’ argument?


It sounds like you want to extract the current column names from the DataFrame and supply them to the Dash DataTable with a custom sorting applied. To sort lexicographically by column name, the columns argument to the DataTable would be columns=sorted(list(your_dataframe)).

1 Like