Posted by devincyu on February 27, 2010 at 5:38am
hi,
I created a content type and a view associated with it, there is a field expiration_date, and for some nodes, this field is empty meaning no expiration date is available.
In a table view, when the nodes are sorted according to expiration_date in a ascending order, those nodes without expiration date come first, however , I could not find a way to make them come at the last.
A more general question is the ordering for empty fields, how to define make them ordered higher rather than lower.
Thanks for your inputs.
Comments
has been struggling with the
has been struggling with the problem, help/insight appreciate!
The same problem here. Any
The same problem here. Any suggestions?
I've solved this problem by
I've solved this problem by altering a query. Here is what I did in case if someone else needs this:
<?php
function myModuleName_views_pre_execute(&$view) {
if($view->name == 'myViewName') {
$view->build_info['query']=str_replace("ORDER BY my_field_name_value", "ORDER BY ISNULL(my_field_name_value), my_field_name_value", $view->build_info['query']);
}
}
?>
You can find the exact name of the field (my_field_name_value) by looking at $view->build_info['query'] (the line which starts with ORDER BY).
Another solution <?phpif
Another solution
<?phpif ($view->name == 'myView') {
$query->orderby[3] = "CASE WHEN myFieldName IS NULL THEN 0 END, myFieldName ASC"; }
?>
The 3 in this case was because I already had an orderby 0, 1 & 2
Thanks, worked great with
Thanks, worked great with some minor adjustments that were specific to my view. :D
// Daniel Kvist @ MR-piloterna