My DataTables View is not sorting properly

When creating or editing a View with the DataTables Extension, you can specify a field to sort by and a sort direction like so:

Sort options with "Business Name" field selected and "ASC" ascending order chosen from dropdown menu

Due to the way the DataTables Extension stores information using the browser, the View may retain a sort setting. 

To clear sorting, add ?cache to the end of the View URL. For example, https://example.com/view/datatables-sort/ becomes https://example.com/view/datatables-sort/?cache — this will force the browser to reload the View without sorting.

You can also permanently fix this by adding the following code to your theme's functions.php file:

add_filter( 'gravityview_datatables_js_options', function( $dt_config, $view_id, $post ) {
    $dt_config['order'] = array();
    $dt_config['stateSave'] = false;
    return $dt_config;
}, 10, 3 );

Read here how to add these code samples to your website: Where to put code samples.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us