Dash Datatable sorting and filtering flags

I saw that some attributes of datatable were renamed. There is no sorting and filtering=True anymore, instead there is a sort_action and filter_action=‘custom’. Is it true that i have to define now a sorting function in a callback like in this callback example:

`@app.callback(
    Output('table-multicol-sorting', "data"),
    [Input('table-multicol-sorting', "page_current"),
     Input('table-multicol-sorting', "page_size"),
     Input('table-multicol-sorting', "sort_by")])
def update_table(page_current, page_size, sort_by):
    print(sort_by)
    if len(sort_by):
        dff = df.sort_values(
            [col['column_id'] for col in sort_by],
            ascending=[
                col['direction'] == 'asc'
                for col in sort_by
            ],
            inplace=False
        )
    else:
        # No sort is applied
        dff = df

    return dff.iloc[
        page_current*page_size:(page_current+ 1)*page_size
    ].to_dict('records')`

or can i somehow prevent this and just get a simple standard sorting and fultering mode for my datatable?

You’re correct. If you set sort_action='custom' or filter_action='custom' then you will need to provide your own sorting implementation.

However, for default behavior you can set the attribute to 'native' to use the previous behavior (default is 'none').

layout = ..,
    dt.DataTable(
            data=[{}], 
            ..
            sort_action='native',
            filter_action='native',
            filter_query='{column}{filter rule} ..',
            page_action='native',
            editable=False,
            ..
    ),
    ...

Easiest place to find information about attributes are the docs https://dash.plot.ly/datatable/reference

1 Like

Works, thank you! :slight_smile: