0

Using Drupal 7 Views with exposed filter on date, the select list is working fine. Problem is that the list is always in ascending order, for example 2000:2014, but we want it the other way round, like 2014:2000 so that the recent years are closer at hand.

I don't mind if the solution (changing date list to descending order) is affecting every select list of the whole site.

Thanks much.

Rising
  • 23
  • 8

2 Answers2

2
function custommodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'views_exposed_form' && $form['#id'] == 'yourviewid') {
    $form['field_name']['value']['#process'][] = date_select_desc_process;
  }     
}


function date_select_desc_process($element, &$form_state, $form) {
  arsort($element['year']['#options']);

  return $element;
}

Hope this helps. If anything more then let me know.

Thanks!! Akhil

0

Can't you just expose also the operator of the filter? (Expose operator at filter setting)

Francis
  • 475
  • 1
  • 6
  • 17
  • We are not talking of ascending/descending of the filtered results. Rather, the filter is giving out a select list; we wish to put items on that list in descending order. Currently, if you pick year 2000 on the list, it is right next, but if you go to year 2014 you will travel to end of the list. – Rising May 31 '14 at 12:16
  • That behavior is in case you are showing the results in ASC order so the select list will be also in ASC order. I would doubt that you can have two separate behaviors there. As an alternative I would mock that select list build it on my own or try a JS trick. While building the custom select list, maybe you could clone the view just for select list and change the URL within a pager template alteration. – Francis Jun 01 '14 at 08:35
  • In fact, in my case the filter is already in descending but select list still ascending. Indeed Views select list is always Ascending by default no matter the filter is ascending or descending. – Rising Jun 02 '14 at 12:51