Views 3

Warning message

JQuery Cycle must be installed in order to run the slideshow. Please go to Status Report for instructions.

In Drupal, when you add exposed filters, it defaults to first word of your select list. But if you want to show all the results on page load then you have to set the exposed filters to "Any" option by default.

To do this:

Add a filter and Expose filter to visitors.

Choose Single filter, give it a label, choose "Is one of" under Operator, and have no terms selected/highlighted in the "Select terms from vocabulary" box. The only option checked under the vocab box is "Display error message."

TIP: CTRL- or CMD-click to unselect the items in the box.

You have to add a simple CSS on your CSS global file.

.ajax-progress-throbber {
    display: none;
}

To remove from a particular view add the view class(.your-view-class) before .ajax-progress-throbber class like:

.your-view-class .ajax-progress-throbber {
    display: none;
}

Drupal 7 views 3 are designed to work on exposed filters, if and only if you use AJAX in your views block. That means you have to enable 
Use AJAX: YES  in you advanced section of Drupal views.

To display the row number generally we can use the views "Global: View result counter (ID)" field in the view but if your view is grouped by
any specific field then it will start displaying the wrong row number. It will show the on the basis of the latest uploaded content.
You can correct this by using PHP and its quite straight forward.
For this you have to create a template inside your theme/templates folders.

1) Name the template
Go to your view -> click on Theme: Information -> Under Style output section, choose a view name which represent your view.
In my case it was a block with name block_1 and view name "document" so i choose " views-view-table--document--block-1.tpl.php" to be
very specific to that block.

2) Create a Global: View result counter (ID) field in your view if you haven't created it.

3) Copy the below code and put it inside your template file.
Below code starts a counter variable and search for "Global: View result counter (ID)" field whose machine name is "counter" and replace it with our counter value. By this way we will get the advantage of displaying all the classes also, which view was already displaying.

/**
 * @file
 * Template to display a view as a table.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $header: An array of header labels keyed by field id.
 * - $caption: The caption for this table. May be empty.
 * - $header_classes: An array of header classes keyed by field id.
 * - $fields: An array of CSS IDs to use for each field id.
 * - $classes: A class or classes to apply to the table, based on settings.
 * - $row_classes: An array of classes to apply to each row, indexed by row
 *   number. This matches the index in $rows.
 * - $rows: An array of row items. Each row is an array of content.
 *   $rows are keyed by row number, fields within rows are keyed by field ID.
 * - $field_classes: An array of classes to apply to each field, indexed by
 *   field id, then row number. This matches the index in $rows.
 * @ingroup views_templates
 */
?>
<?php print $attributes; ?>>
   <?php if (!empty($title) || !empty($caption)) : ?>
     <?php print $caption . $title; ?>
  <?php endif; ?>
  <?php if (!empty($header)) : ?>
    
      
        <?php foreach ($header as $field => $label): ?>
          >
            <?php print $label; ?>
          
        <?php endforeach; ?>
      
    
  <?php endif; ?>
  
    <?php $count = 1;
     foreach ($rows as $row_count => $row): ?>
      >
        <?php foreach ($row as $field => $content): ?>
          <?php print drupal_attributes($field_attributes[$field][$row_count]); ?>>
            <?php if($field == 'counter') {
            	  print $count;
            	}
            	else{
            		print $content;
            	} ?>
          
        <?php endforeach; ?>
      
    <?php $count++;
    endforeach; ?>
  

4) Flush the cache.

To hide the views on a page programatically, you have to use hook_views_pre_view. This is useful when you have same view rendering on a page more than one time and you have to hide one of the display mode. For example, it might be possible that your page is rendering a view and a block of a view . Then you might want to hide that view and display a block only.

/**
 * Implementation of hook_views_pre_view().
 */
function YOUR_MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) {
  //Check the view name and display mode of view, then hide the view.
 // Display id is the machine name of the view or block inside a view
   if ($view->name == 'view_machine_name' && $display_id == 'document_page') {
		$view->executed = TRUE;
   }
 }

Possible Use-Case : You want to show a list of "Countries" and there related "Cities". But you want only related cities to be shown on the page .
 To do this place country as parent term and all the cities as sub-term. So construct a vocabulary like this :

INDIA 
- Delhi
 - Rajashtan
- Chandigarh
- Gujrat

USA
- Alabama
- Alaska
- Georgia
- Illinois

Then use simple module called "Simple Hierarchical Select" https://drupal.org/project/shs or you can also use "Hierarchical Select" https://drupal.org/project/hierarchical_select
But hierarchical select has more functions but if you have taxonomy related task only then you can use only SHS as for the above use-case.

Now go to the content type -> manage fields -> select term reference-> simple hierarchical select Or create a field like this if you haven't created.
Now go to your views or create a view if you haven't already created => select the "your-field-name" (hierarchical select ) from filters and force it to some depth. Expose this filter for users.

Then it will show first country name and then child term which are city names.

 

To Change the text of a option value with in a text box use the following code :
In below example just change the select id name "edit-field-category-tid option" with your select id and 1,2,3,4 represent the order of terms in selectbox

$("#edit-field-category-tid option").eq(1).text("Bares y Restaurantes");
$("#edit-field-category-tid option").eq(2).text("Grandes Superficies");
$("#edit-field-category-tid option").eq(3).text("Mayoristas");
$("#edit-field-category-tid option").eq(4).text("Al Detal");

OR

$('select option:contains("Online")').text('offline');

Please Note : You can use the above code to change the values on drupal views filter expose form select box. The possible scenario is to change the text on change on language. But for that you have to change
the "Ajax : No " inside your views.

In Drupal 6 the queries are by default showing in the views 2 

But as of Drupal 7 things get changed and now if you want to see queries at the end of running view. You have to go to Structure >> Views >> Settings >> Inside Live preview Settings Box :

Check the option "Show the SQL query" and Save it. 

Subscribe to RSS - Views 3