Drupal 6.x Views "Alpha Pager" but with Numerics?

I recently had a project that required a Page View (using Defaults, of course). The view generated a bunch of names, and because of this, I had to use an Alpha Pager (i.e. - A || B || C || …) to leverage usability concerns. I dodged a bullet this time due to the output consisting solely of names, so numerics were not required, but if they were, how could they be implemented?

For my purposes, I did the following (for names only, that is, but maybe this could be used as a stepping stone for what I’m wanting here):

1.) Created a view that had the “name fields.”
2.) I then needed an argument of type node => name and set it to a glossary configuration using a 1-character limit (which is later used for the Alpha Pager).
3.) In the header space (here is where the actual Alpha Pager comes in), I used the following code I found somewhere on the 'net:


<?php
print l(t('All'), 'names_output') . ' ';
for ($char = ord('a'); $char <= ord('z'); $char++) {
  print l(strtoupper(chr($char)), 'names_output' . '/' . chr($char)) . ' ';
} // A-Z pager @bro
?>

All this does is basically output the word “All” and the letters A-Z as links but which get used as arguments for the View’s argument configuration. In other words, it uses the “All” and A-Z links as filters of sorts for the output the view creates. It’s pretty cool considering it doesn’t rely on additional mods or anything. But the only thing remaining is using this same approach to support numerics, which is something I was never able to find any answers on.

SO… I ask the following:

How could numerics be implemented into this approach?

I.e. -

ALL || 0-9 || A || B || C || … || X || Y || Z

(Whereby clicking on “All” outputs everything in the view, clicking on 0-9 [or by expanding it to individual numbers] outputs the respective numeric field value, clicking on the letters, etc.)

Any input / insight into this is appreciated.

That is very cool… I haven’t used an alpha pager with Drupal which seems weird because I’ve used them in various other single–purpose, custom CMS like systems. In fact I was just thinking about this the other day while considering how to go about a project listing firms where an Alpha pager would be necessary.

I have a question about the “name field”. What is the type of view and what is the name field you are referencing?

Andrew

Andrew, the name field is really just any field one could use that has letters in it. So this would apply to the generic “title” field that comes out-of-the-can, so-to-speak, but can also apply to a CCK field, too. Say you create a first_name field or something like a species_field–whatever–the argument’s configuration will take whatever value exists for that given field and look at that first character (so again, just as long as it has letters). I’m skipping over some steps in explaining this, but if you’re curious about anything or unsure about something, let me know and I’ll try to follow-up.

As for the type of view, it was a page view but really, just using the defaults. I added the page view aspect because I needed to use this to output a basic menu of sorts.

Ok, yes… That’s what I thought but I wanted to be sure. I’m going to try an example on a dev testing site I have to see how it works. I think I’ll try it with users and see how an alpha pager works and then I’ll see if I can get the numerical part to work too.

Great! I’ll try to come back later and export a basic version of this to post on here (with more details about the setup). Maybe that can help.

Very cool! Thanks and I’ll see if I can get the numeric part working.

Andrew -

Here’s the export of a generic alpha pager view I just created (I would’ve had it on here sooner but I’ve been pretty busy lately). Hope it helps (it’s a page view that does nothing more than extract the various “Stories” one has created and outputs them all on this page the view created with an alpha pager–pretty straightforward but if you have any complications, let me know and I’ll try to help out with setting it up):

$view = new view;
$view->name = 'alpha_pager_example_page_view';
$view->description = 'Alpha Pager Example (Page View)';
$view->tag = 'example';
$view->base_table = 'node';
$view->core = 6;
$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(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'absolute' => 0,
      'link_class' => '',
      'alt' => '',
      'rel' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 1,
    'empty_zero' => 1,
    'hide_alter_empty' => 1,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'title' => array(
    'default_action' => 'ignore',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'glossary' => 1,
    'ignorecase' => 0,
    'limit' => '1',
    'case' => 'none',
    'path_case' => 'lower',
    'transform_dash' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      2 => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_taxonomy_tid_term_page' => 0,
    'default_taxonomy_tid_node' => 0,
    'default_taxonomy_tid_limit' => 0,
    'default_taxonomy_tid_vids' => array(),
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'page' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_php' => '',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('header', '<?php
print l(t(\\'All\\'), \\'alpha_pager_page_example\\') . \\' \\';
for ($char = ord(\\'a\\'); $char <= ord(\\'z\\'); $char++) {
  print l(strtoupper(chr($char)), \\'alpha_pager_page_example\\' . \\'/\\' . chr($char)) . \\' \\';
}
?>');
$handler->override_option('header_format', '3');
$handler->override_option('header_empty', 1);
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'alpha_pager_page_example');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));


Note: “alpha_pager_page_example” is the page URL you would use to get to the page whereas “alpha_pager_example_page_view” is the actual View itself.

:slight_smile: