I have a view which groups rows in a table according to the first letter of the title. Some of the letters are uppercase and some are lowercase. View treats the upper and lower case as separate groupings (see image attached) but I want them to be grouped case-insensitively.

I've checked my db tables are ci and I've tried to alter the query using hook_views_query_alter but haven't managed to find a solution yet.


enter image description here


The query executed is corrected, when adding a count value on the grouping (for example when adding a glossary), you will get a count with merged grouping (case-insensitive).

The problem here is when adding a Grouping field with Use rendered output to group rows enabled, it will do the grouping with case-sensitive because a B is not equal to b. To resolve the problem, you can implement YOURMODULE_views_pre_render(), and clone the institution name to a new datamember and transform this to uppercase. To notify the view that the grouping field should use the new created datamember, you can change its alias.

Here is some sample code

function YOURMODULE_views_pre_render(&$view)
    // only execute code on 'your_view_name'
    if ($view->name !== 'your_view_name') {

    // 'title_grouping' is the field used to regroup the nodes
    // 'node_title_upper' is the new datamember that will be added to node object
    $view->field['title_grouping']->field_alias = 'node_title_upper';

    // loop through each node, and assign an uppercased node title to the 'node_title_upper' datamember
    foreach ($view->result as $result) {
        $result->node_title_upper = strtoupper($result->node_title);
  • nice answer.... – Mr. J Nov 28 '14 at 7:54
  • @mike Vranckx could you please explain how should I use a newly created property (node_title_upper) in my view? – Dmytro Pastovenskyi Mar 25 '15 at 14:30
  • You can't use the created property within inside your view settings. This property is only used internally to change the behavior of the sorting. – Mike Vranckx Mar 27 '15 at 12:39

In Drupal 8, this can be done pretty effortless thanks to Twig. Just override the output of the grouping field with its value plus Twig's built-in uppercase filter (|upper or |capitalize), see screenshot: enter image description here


Quick and easier way.

If you are using views PHP field, Then convert required field to uppercase using strtoupper() function right there.

Then group views result by this converted PHP field.

  • You should avoid enabling the PHP Filter module as it has security implications. – Scott Joudry Aug 27 '14 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.