A view with exposed sort: can i turn off 'grouping field' for different sort criteria? My Views list of events is grouped by the date (using the Grouping Field checkbox in the Style settings).

But my exposed Sort Criteria can sort the list by either date or by name.

An alphabetical list of events grouped by date really doesn't make any sense. 

What would make sense is for the Grouping Field to turn off when the Sort Criteria is by name.

I'm thinking either i do two views, and my template decides which view to embed depending on the URL query. Or perhaps a views hook like hook_views_query_alter() could turn off the Grouping Field depending on the circumstances?
Ok, i think i've managed it with a Views hook. Took an hour's worth of tinkering. I plopped this into my template.php...

/** Find out what the sort criterion is.
    @return The sort criterion fieldname. IMPORTANT: this isn't sanitised!
*/
function MYTHEME_get_sort_by() {
    if (isset($_GET['sort_by']))
        return $_GET['sort_by'];    
}

/** Turn off Views grouping-field when sorting by title.
*/
function MYTHEME_views_pre_build(&amp;$view) {
    if ($view-&gt;name=='event_programme') {
        if (MYTHEME_get_sort_by()=='title')
            $view-&gt;display_handler-&gt;options['style_options']['grouping']='';    
    }
}