I have a view and am listing a bunch of data from different content type .

What i need is , i have to list the data according to the date field given . That

is i have to filter the date in between two dates , Is this possible ?


I used the exposed filter as follows :

enter image description here enter image description here

The problem of this filter is i have to manually enter the date in date field . can i have data field which can select the date as in datepicker ?

  • you can see my answer in similar question if it suits you drupal.stackexchange.com/a/225295/59051 – Ashish Deynap Jan 12 '17 at 9:21
  • Will it be possible to apply datepicker on hook_views_query_alter ? – KTM Jan 12 '17 at 9:24
  • Cannot say as i have not used it but believe it should be working in hook_views_query_alter(). For that, use datepicker in corresponding view and alter the view query inside the hook – Ashish Deynap Jan 12 '17 at 11:27
  • Okay i applied datepicker to the field which right away solved my problem , as Jquery Ui date picker was readily available in D8 – KTM Jan 12 '17 at 12:44
  • Did you figure it out? – Tritof Nov 14 '17 at 13:04

I had a similar problem and the solution I did was to add a date Picker to that page or view or exposed form and hide the current field in the twig file and add another with datepicker added to it

You can add a library to that view

function YOUR_THEME_NAME_preprocess_views_view(array &$variables) {
  if (isset($variables['view'])) {
    if ($variables['view']->id() == "VIEW_ID") {
      if ($variables['view']->getDisplay()->display['id'] == "VIEW_DISPLAY_ID") {
        $variables['#attached']['library'][] = 'YOUR_THEME_NAME/date-picker';

It is explained in this answer: How to configure an exposed filter in a view using a date picker?

| improve this answer | |

In 7 you can do this with Better Exposed Filters by selecting the jQuery UI datepicker option in the screen of your screenshot. There is an alpha out for 8.

The Better Exposed Filters module replaces the Views' default single- or multi-select boxes with radio buttons or checkboxes, respectively. Description fields and Select All/None links can be added to exposed filters to make for a better user experience.

Views Filters is a powerful tool to refine the results returned by a given view. When you expose a filter, you allow the user to interact with the view making it easy to build a customized, advanced search. For example, exposing the node type field as a filter lets your site visitor limit their search queries to just blog entries. Better Exposed Filters gives you greater control over the rendering of exposed filters.

| improve this answer | |
  • am úsing drupal 8 – KTM Jan 12 '17 at 9:18
  • 1
    I know, so try the module for 8. It's alpha but actively developed. – Ruben Beekman Jan 12 '17 at 9:25

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.