I am trying to expose data fetched from remote API and stored to $user object. I have accomplished that with a custom views handler suggested in this post Custom views handler without table.

However, I need to add sorting and filtering, so any help will be great.

This is the custom views field handler code.

 * A handler to provide a field that shows the license type.
 * @ingroup views_field_handlers
class views_handler_apms_license extends views_handler_field {

  function query() {
    // do nothing -- to override the parent query.

  function option_definition() {
    $options = parent::option_definition();

    // Override the alter text option to always alter the text.
    $options['alter']['contains']['alter_text'] = array('default' => TRUE);
    return $options;

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    // Remove the checkbox

  function render($values) {
    $user = user_load($values->uid);
    if (isset($user->apms['userLicense'])) {
      return $user->apms['userLicense'] ? t('BASIC') : t('FREE');
    else {
      return NULL;
  • I'm sure I've seen it asked already, 2 or 3 times. But I can't recall to see this answered :( Also, "I have accomplished that - can you show / tell us how? maybe it will gove us some idea about answer.
    – Mołot
    Dec 22, 2013 at 22:25
  • Thank you for the question @Mołot, I use a custom field handler with the following code pastebin.com/WwEMsQ6A.
    – didaka
    Dec 23, 2013 at 13:15
  • Great question. I'm struggling with the same thing
    – aross
    Feb 4, 2014 at 13:16
  • Can you not create a custom filter handler to filter as your require? Feb 7, 2014 at 21:00
  • It has never been solved! Maybe some of us can solve it for the community!
    – Ehsan
    Mar 2, 2015 at 16:07

2 Answers 2


Ok, just to put another idea out there...

If your data set is not too big then output all the unfiltered unsorted data to an html table, and then use a jQuery plugin to do all your sorting and filtering client side. Something like this would be suitable.

  • This is what the problem I was facing. The data set was huge and processing it on the server side was very expensive. The solution was to render all on one page and then use the jQuery plugin mentioned above for sorting, filtering and paging.
    – didaka
    Mar 2, 2015 at 19:34

You can use the post_execute() method on your handler to remove entries from the list of all results. This is certainly a bit tricky but it works.

  • wouldn't pre_render also work? if so, is post execute a better place to handle sorting?
    – awm
    Feb 6, 2014 at 19:08
  • I would argue that everything the execution result should be done in post_execute, if you change stuff related with rendering do it in pre_render. Feb 6, 2014 at 19:55
  • 1
    This is not the right way of doing it. Consider pagination/lots of records. post_execute/pre_render will act current result set only not on all the available records. Feb 7, 2014 at 5:10
  • Well, if you really need to support those cases you need to store values in the databsae ... there is simply no way around that. Feb 7, 2014 at 9:14
  • Yeah, I was afraid that it wouldn't be possible. I tested post_execute as well and noticed it was limited because it contains the result of the query (which inckudes pagination). So it's not the answer I'd hoped for, but awarding bounty nonetheless.
    – aross
    Feb 10, 2014 at 10:03

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.