This is an interesting issue and I can't quite pin down the point of failure. I have a view that is sorting data from node_counter, but some of the node_counter_totalcount data has null values. The query executes fine and the $view->total_rows value reports the correct row count, but the records that have the null values appear to be excluded from the display of the view. I've included the view definition below on the chance that might be helpful.
$view = new view;
$view->name = 'faceplates';
$view->description = 'faceplates';
$view->tag = 'faceplates';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = '0';
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'field_face_plate_value' => array(
'id' => 'field_face_plate_value',
'table' => 'node_data_field_face_plate',
'field' => 'field_face_plate_value',
'label' => 'Faceplate',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'relationship' => 'none',
'link_to_node' => 0,
),
'field_user_last_first_value' => array(
'id' => 'field_user_last_first_value',
'table' => 'node_data_field_user_last_first',
'field' => 'field_user_last_first_value',
'label' => 'Last, First',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'relationship' => 'none',
'link_to_node' => 0,
),
));
$handler->override_option('sorts', array(
'field_sort_index_value' => array(
'id' => 'field_sort_index_value',
'table' => 'node_data_field_sort_index',
'field' => 'field_sort_index_value',
'order' => 'DESC',
'relationship' => 'none',
),
'totalcount' => array(
'id' => 'totalcount',
'table' => 'node_counter',
'field' => 'totalcount',
'order' => 'DESC',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'tid' => array(
'id' => 'tid',
'table' => 'term_node',
'field' => 'tid',
'default_action' => 'ignore',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => TRUE,
'override' => FALSE,
'items_per_page' => 25,
),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'empty',
'break_phrase' => 1,
'add_table' => 0,
'relationship' => 'none',
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_php' => '',
'validate_argument_node_type' => array(
'usernode' => 0,
'include' => 0,
'job_listing' => 0,
'orgnode' => 0,
'page' => 0,
'pressrelease' => 0,
'promo' => 0,
),
'require_value' => 0,
'reduce_duplicates' => 0,
'validate_argument_vocabulary' => array(
'112' => 112,
'111' => 111,
'100' => 100,
'101' => 101,
'109' => 109,
'102' => 102,
'117' => 0,
'114' => 0,
'116' => 0,
'115' => 0,
'110' => 0,
'108' => 0,
'119' => 0,
'118' => 0,
'1' => 0,
),
'validate_argument_type' => 'tid',
),
'field_co_id_value' => array(
'id' => 'field_co_id_value',
'table' => 'node_data_field_co_id',
'field' => 'field_co_id_value',
'default_action' => 'ignore',
'style_plugin' => 'default_summary',
'style_options' => array(
'count' => TRUE,
'override' => FALSE,
'items_per_page' => 25,
),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'glossary' => 0,
'limit' => '0',
'case' => 'none',
'path_case' => 'none',
'transform_dash' => 0,
'relationship' => 'none',
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_php' => '',
'validate_argument_node_type' => array(
'usernode' => 0,
'include' => 0,
'job_listing' => 0,
'orgnode' => 0,
'page' => 0,
'pressrelease' => 0,
'promo' => 0,
),
'validate_argument_vocabulary' => array(
'117' => 0,
'114' => 0,
'112' => 0,
'111' => 0,
'100' => 0,
'116' => 0,
'115' => 0,
'110' => 0,
'108' => 0,
'119' => 0,
'118' => 0,
'1' => 0,
'101' => 0,
'109' => 0,
'102' => 0,
),
'validate_argument_type' => 'tid',
),
));
$handler->override_option('filters', array(
'status' => array(
'id' => 'status',
'table' => 'node',
'field' => 'status',
'operator' => '=',
'value' => 1,
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'relationship' => 'none',
'expose_button' => array(
'button' => 'Expose',
),
),
'field_profile_display_value' => array(
'id' => 'field_profile_display_value',
'table' => 'node_data_field_profile_display',
'field' => 'field_profile_display_value',
'operator' => 'or',
'value' => array(
'2' => '2',
),
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'relationship' => 'none',
'expose_button' => array(
'button' => 'Expose',
),
'reduce_duplicates' => 0,
),
'field_face_plate_value' => array(
'id' => 'field_face_plate_value',
'table' => 'node_data_field_face_plate',
'field' => 'field_face_plate_value',
'operator' => '!=',
'value' => 'NULL',
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'case' => 1,
'relationship' => 'none',
'expose_button' => array(
'button' => 'Expose',
),
),
));
$handler->override_option('access', array(
'type' => 'none',
'role' => array(),
'perm' => '',
));
$handler->override_option('use_ajax', '1');
$handler->override_option('items_per_page', 24);
$handler->override_option('use_pager', '1');
$handler = $view->new_display('page', 'NameSort', 'page');
$handler->override_option('sorts', array(
'field_user_last_first_value' => array(
'id' => 'field_user_last_first_value',
'table' => 'node_data_field_user_last_first',
'field' => 'field_user_last_first_value',
'order' => 'ASC',
'relationship' => 'none',
),
'field_sort_index_value' => array(
'id' => 'field_sort_index_value',
'table' => 'node_data_field_sort_index',
'field' => 'field_sort_index_value',
'order' => 'DESC',
'relationship' => 'none',
),
'totalcount' => array(
'id' => 'totalcount',
'table' => 'node_counter',
'field' => 'totalcount',
'order' => 'DESC',
'relationship' => 'none',
),
));
$handler->override_option('path', 'fp_name');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
Comments
Comment #1
matt_paz commentedHmm. I'm not sure that what I'm experiencing is directly related to this or not ... it appears that if I turn off ajax paging, I get the expected results? I'm going to have to do some more digging.
Comment #2
merlinofchaos commentedWell, you've definitely stumped me a little bit. I've asked Jeff Eaton to help look at this as he wrote the statistics.module implementation, but this may be related more to output than that. I'm not sure.
Could you do me a favor and post the query the View generates during live preview?
Comment #3
matt_paz commentedHmm. I think this might not be an issue with views or statistics at all. I was manipulating the view from a script and that script was being by-passed when using AJAX (vs. regular paging) ... so it was correct when viewing the first page, and incorrect when viewing the next. The stats issues appears to have simply been a coincidence. I've changed this from a bug report to a support request.
I'd love to get some insight on how best-of-breed techniques for integrating with views. I REALLY LOVE the AJAX paging capabilities, so I'd love to get some insight into the best technique for modifying/interoperating with a view. If any views experts wanted to touch base, please contact me.
Comment #4
matt_paz commentedooops ... meant to change the status too/category. Closing it now.
Comment #5
merlinofchaos commentedCan you explain what it is you're trying to accomplish?
Comment #6
matt_paz commentedSure, right now, I'm invoking/embedding a view (not sure what the right terminology is there) from a script and varying the filters and arguments based on information from information in the user object and from information in the query string. Are there any rule of thumbs for doing something like that. Hmm. Looking at it now, I'm wondering if the problem might be that when I'm invoking the view, I'm modifying the filter in addition to specifying the arguments? That shouldn't be a problem should it?
I'm also using the query that views creates as a source for some faceted navigation (aka filters) that I'm presenting to the user, but I don't appear to be having problems there ... just not sure that I'm doing it the "right" way either.
Comment #7
markus_petrux commentedHi,
I'm also having this problem. I have a default view, which is pretty simple. Only node title and changed date. The user can modify this view to add more fields, change other options, etc. and then the module provides methods to embed the view under different contexts, related to different nodes. I load the (maybe customized) default view, then I dynamically generate arguments that are also populated before the view is executed. It works just fine.
The problem comes when ajax is enabled. The first time the embeded view is rendered when the whole page is loaded, it looks as it should, but when the user clicks on column header to sort, or use the pagination, the ajax response returns a view without all modifications I did initially.
I suspect the ajax request is rebuilding the original view, so I'm wondering how I could tell the ajax code in views to invoke a callback or something where I could reapply the customization to the view before it is returned back to the browser.
It sounds like a triycky thing. Maybe I should store the view somewhere temporarily so that the ajax request knows it is a customized version of the original view.
How to provide ajax functionality to a view that's been generated dynamically? Is that possible? Suggestions?
Thanks
Comment #8
markus_petrux commentedWell, I've been looking at the code behind views ajax, and well, it's not possible. The views ajax callback simply processes the original view.
So we need to find a way to intercept that process, identify the view we're interested in, and perform the dynamic changes to the view settings before views ajax callback executed the preview() method. To accomplish this, there's a number of hooks views exposes, for example hook_views_pre_view(), but I tried to add a relationship and a couple of arguments from here, and it doesn't seem to work. :(
Another possibility that come to mind, is trying to use a method that alters the callback path of the ajax request and then use my own menu callback. But here, I'm not sure how to alter this path.
Any advice would be greatly appreciated.
Comment #9
markus_petrux commentedPlease, let me turn this issue into a feature request with a pretty simple patch that would allow ajax views to be dynamically customized before they are executed.
I have also created a discussion at g.d.o. where I tried to explain what I'm trying to do, which is something I think opens the door to a lot of possibilities.
http://groups.drupal.org/node/22254
Comment #10
markus_petrux commentedWhile it would be nice if the patch in #9 was included in views, I wanted to say that I won't need it as I have decided I'll use hook_views_pre_view() which is something I also need to implement to dynamically configure page displays for node back references.
Comment #11
merlinofchaos commentedI think I'm going to stick with the existing hooks. I don't see a *real* need to treat the ajax'd view separately unless I'm missing something.