0

I have a custom table exposed to view with a column of type int where I am storing current time stamp. while exposing the custom table I have kept views filter handler as "views_handler_filter_date", but this is not allowing to create expose filter with month and year granularity.How can I get month and year granularity for my date_of_purcahse

Here is the snippet exposing the field to views.

  $data['jh_report']['date_of_purchase'] = array(
    'title' => t('Date of purchase'),
    'help' => t('Date of last purchase for current month'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
    ),
  );

1 Answer 1

0

In order to get month, year granularity we can use date handler as defined by date module so while exposing field to use it will be all about choosing the right filter handler so I used "date_views_filter_handler_simple" handler.

Code while exposing the custom table field with proper filter handler.

$data['jh_report']['date_of_purchase'] = array(
    'title' => t('Date of purchase'),
    'help' => t('Date of last purchase for current month'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'filter' => array(
      'handler' => 'date_views_filter_handler_simple',
    ),
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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