1

What makes a field sortable in views?

I have 5 fields output in a table and only two (Node Title and an int) are sortable the rest (mixture of content taxonomy and node reference) are not sortable.

Is it possible to add in this functionality via code?

  • 2
    It is right there in the table style settings. – Capi Etheriel Sep 13 '11 at 15:39
  • No only the two fields I mentioned are sortable. – digital Sep 13 '11 at 15:43
2

The query_alter function allows build a custom module with the posibility of change sort order of a view. With this function you can add directly to your sql the respective declaration to sort results.

look this guide http://www.adworkshop.com/blog/2011/05/drupal-6-tutorial-exposed-sort-views-2 that show you how to create your query_alter and create the respective html control to your view (in this case is a dropdown menu).

this is the query_alter function:

function example_exposed_sort_views_query_alter(&$view, &$query) {
if( isset( $_GET['sortoptions'] ) ) {
if ( $_GET['sortoptions'] == 'az' )
 $query->orderby[0] = 'node_title ASC';
else if ( $_GET['sortoptions'] == 'za' )
$query->orderby[0] = 'node_title DESC'; } }

and this is the example of html control using a dropdown menu using in this case the template views-exposed-form.tpl.php.

<?php
$sortOp = '';
if ( isset($_GET['sortoptions']) ) $sortOp = $_GET['sortoptions'] ;
?>
<label>Sort Name</label>:
<input type="radio" id="sortoptionsA" name="sortoptions" onchange="javascript:$(this.form).submit();" class="form-submit" value="az" <?php if ($sortOp == 'az') print "checked"; ?> />A-Z
<input type="radio" id="sortoptionsZ" name="sortoptions" onchange="javascript:$(this.form).submit();" class="form-submit" value="za" <?php if ($sortOp == 'za') print "checked"; ?> />Z-A
0

Did you try these modules: lineage and maybe views_bonus ?

I searched on drupal.org regading your question and here are some findings:

According to Support node sort by taxonomy vocabulary for Taxonomy module (read here) the standard feature to sort by taxonomy vocabulary was postponed till Drupal 8 (D8).

Here you can find more related information:

This guide explains how to "Create a view on a node reference field" and how to set the view sort criteria for node reference fields.

  • By sortable I mean the ability to click on the title and sort alphabetically or via asc desc integer. – digital Sep 12 '11 at 15:55
0

As barraponto commented, it is right there in the table style settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.