Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3601622
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:38:40+00:00 2026-05-18T20:38:40+00:00

When using views without Ajax, it’s easy to access the $view->result array using hook_views_pre_render().

  • 0

When using views without Ajax, it’s easy to access the $view->result array using hook_views_pre_render(). But how can I access the $view object if I’m using Ajax to filter my view?

I want to use to result in different Javascripts and forms, therefore the best solution would be to put $view->result in the Drupal.settings object.

Is this possible? I’ve found hook_ajax_data_alter() but I don’t know how to use it, or if it’s the right way to go.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:38:41+00:00Added an answer on May 18, 2026 at 8:38 pm

    Ok, so I’ve found a somewhat good looking solution.

    /**
     * Implementation of hook_ajax_data_alter().
     */
    function request_ajax_data_alter(&$object, &$type, &$view) {
      $array = FALSE;
      // Detect whether the data being altered is an array.
      if (is_array($object)) {
        $object = (object) $object;
        $array = TRUE;
      }
      $object->scripts = $extra['scripts'];
      $object->css = $extra['css'];
      if (!isset($object->__callbacks)) {
        $object->__callbacks = array();
      }
    
      // Add the view result to the object.
      $object->view_result = $view->result;
    
      // Set the custom event as a callback.
      $object->__callbacks[] = 'Drupal.request.saveResult';
    
      // Cast back to an array if necessary.
      if ($array) {
        $object = (array) $object;
      }
    }
    

    I’ve simply added the $view->result to the $object, and added my custom callback, which adds $view->result to the Drupal.settings object.

    I tried to add a callback directly to the $view object, but didn’t succeed, so this will do for now.

    Please let me know if there’s a better way to do this =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using views without Ajax, it's easy to access the $view->result array using hook_views_pre_render().
How can we create 2 table views in a single view without using section
I'm currently re-using a partial on two different views. View A View B The
I've developed an application at working using MySQL 5, that uses Views to access
I wanted to generate one fix view using interface builder, but the size of
I wonder if I can test landscape view using simulator?
I'm using Views dropdown filter (with tags) and it works great. However I would
Using the CRM views, is there a way to retrieve a list of all
I'm collecting metadata using the sys.* views, and according to the documentation, the sys.identity_columns
I am developing an application using MVC Preview 5. I have used typed views.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.