I am trying to change the 'Grouping Field' of a view dynamically, depending on which exposed sort the user selects.

It seems that in past times the grouping was accessible via the following in the template.php file:

function MYTHEME_views_pre_build(&$view) {
...
      $view->display_handler->options['style_options']['grouping'] = $foo;    
}

However, this no longer appears to be the case and I cannot figure out what it has been replaced with.

Anyone have any ideas or alternatives of how I can accomplish this? Any help is greatly appreciated.

Comments

dblais’s picture

Try

MODULE_views_pre_view(&$view) {
$view->display['default']->handler->options['style_options']["grouping"][0]["field"]="field_name";
}

skywalk’s picture

Thanks @dblais - Unfortunately I do not have a way to test this right away, but I'm glad you had an answer for me for the next round!

RenatoG’s picture

Issue summary: View changes
Status: Active » Reviewed & tested by the community

Hi people, how are you?

I tested and really is possible make it using hook.

Thanks for help @dblais

RenatoG’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.