You are here

Views 3

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."

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.

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.

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 :

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

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.