Skip to content

Instantly share code, notes, and snippets.

@sirBlond
Created October 22, 2012 23:58
Show Gist options
  • Save sirBlond/3935653 to your computer and use it in GitHub Desktop.
Save sirBlond/3935653 to your computer and use it in GitHub Desktop.
Drupal 7 simple views sorting realization via JavaScript
<script type="text/javascript">
function goURL(){
var url = document.getElementById("selectID").options[document.getElementById("selectID").selectedIndex].getAttribute("value");
window.location = url;
}
</script>
Sort by&nbsp;
<select id="selectID" onchange="javascript:goURL();">
<option value="?sort_by=title&sort_order=ASC">By title(ASC)</option>
<option value="?sort_by=created&sort_order=ASC">By creation date(ASC)</option>
<option value="?sort_by=field_CustomFieldName_value&sort_order=ASC">By your custom field (ASC)</option>
<option value="?sort_by=title&sort_order=DESC">By title(DESC)</option>
<option value="?sort_by=created&sort_order=DESC">By creation date(DESC)</option>
<option value="?sort_by=field_CustomFieldName_value&sort_order=DESC">By your custom field(DESC)</option>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment