I have created custom profile fields using the date data type so that I can record each user's various expiration dates. I am trying to create a User view with views using the "table" style to display all of those dates. That's not the problem...

I just can't sort any of the table's columns by date.

I essentially wanted a view that can display all the users and their corresponding expiration dates (it's a list of cab drivers and their motor vehicle record expiration dates). It would be nice if I could sort the tables by the dates either ascending or descending, etc. I know where to select whether a column is sortable or not, but the checkbox is unavailable for the date fields.

Is this simply a feature that has been overlooked by the views coders, or a genuine bug?

I imagine that it is fairly important to be able to create views of userlists that can sort custom profile fields like dates.

CommentFileSizeAuthor
#9 viewCCKDateFieldSortable.jpg67.37 KBsomebodysysop

Comments

merlinofchaos’s picture

Status: Active » Closed (won't fix)

It is neither an oversight nor a bug. The way the profile module stores dates is a serialized array,which is not sortable in sql.

Doomd’s picture

Can you suggest another simple way to have this data sortable by date?

karens’s picture

There is no way to do this, that's why Views doesn't do it. It's because there is no way to sort on a field that stores its data in a serialized array. The only 'workaround' is to use a different kind of field for the date, like the CCK date field, and migrate all your dates to that field, but then you would also have to use a module like the Bio module so you have a way to associate the date field with a user, which would require you to make major changes to the way your site is set up.

The problem should go away in D7 where we have real fields for Users, but that won't help you in D6.

So no, there is no 'simple' way to do it. Sorry.

somebodysysop’s picture

For the record, the CCK date field does not appear as sortable in views tables either. At least, in the two sites in which I have tried it. The date itself is a varchar format in the database so it should be sortable:

content_field_eventstart

# vid: int unsigned, 10
# nid: int unsigned, 10
# delta: int unsigned, 10
# field_eventstart_value: varchar, 20
# field_eventstart_value2: varchar, 20
# field_eventstart_rrule: text, 65535

The dates themselves are formatted in a way so that they would be easily sorted in sql:

select * from content_field_eventstart
vid 	nid 	delta 	field_eventstart_value 	field_eventstart_value2 	field_eventstart_rrule
4326 	4290 	0 	2009-07-09T15:48:00 	2009-07-09T15:48:00 	
6 	6 	0 	2006-06-24T20:00:00 	2006-06-24T23:55:00 	
7 	7 	0 	2006-07-07T19:00:00 	2006-07-08T00:30:00 	

I have posted an issue here: http://drupal.org/node/517126

But, as I read this issue and date cck field was recommended, I had to respond.

astridman’s picture

um, merlinofchaos, definitely not blaming you, it's out of your hands. Having said that...this is ******* absurd. A major open-source framework in it's 6th iteration and you can't even sort by DATE????

how on earth do I explain this to the client?

dawehner’s picture

If you use content profile you can do it. Perhaps you can implement your own profile type date2 which saves time as timestamp. But currently as merlinofchaos said, it is really impossible to sort it.

somebodysysop’s picture

I'm still hoping to get a response to my point in #4 that cck date fields, while recommended as a solution to this, are not sortable either.

merlinofchaos’s picture

SomebodySysop: You're wrong. CCK date fields are sortable. I just checked.

astridman: Welcome to open source. Please submit patches. This is not an appropriate place to gripe about these things. Drupal has a lot of inadequacies, many of them magnified by individual needs. With a little bit of PHP it should not be too difficult to add a date field to a user that is sortable, but you have to do the legwork. Possibly all of Drupal could benefit from this. But I recommend against griping about free software without providing contributions.

somebodysysop’s picture

StatusFileSize
new67.37 KB

SomebodySysop: You're wrong. CCK date fields are sortable. I just checked.

You are right. I should have made myself more clear. An export of the cck date field I created does say it is sortable:

$content['fields']  = array (
  0 => 
  array (
    'label' => 'Start Date',
    'field_name' => 'field_eventstart',
    'type' => 'date',
    'widget_type' => 'date_select_repeat',
    'change' => 'Change basic information',
    'weight' => '-3',
    'default_value' => 'now',
    'default_value2' => 'same',
    'default_value_code' => '',
    'default_value_code2' => '',
    'input_format' => 'm/d/Y - g:i:sa',
    'input_format_custom' => '',
    'year_range' => '-3:+3',
    'increment' => '1',
    'advanced' => 
    array (
      'label_position' => 'above',
      'text_parts' => 
      array (
        'year' => 0,
        'month' => 0,
        'day' => 0,
        'hour' => 0,
        'minute' => 0,
        'second' => 0,
      ),
    ),
    'label_position' => 'above',
    'text_parts' => 
    array (
    ),
    'description' => '',
    'group' => false,
    'required' => 0,
    'multiple' => 1,
    'repeat' => 1,
    'todate' => 'optional',
    'granularity' => 
    array (
      'year' => 'year',
      'month' => 'month',
      'day' => 'day',
      'hour' => 'hour',
      'minute' => 'minute',
    ),
    'default_format' => 'medium',
    'tz_handling' => 'site',
    'timezone_db' => 'UTC',
    'repeat_collapsed' => '1',
    'op' => 'Save field settings',
    'module' => 'date',
    'widget_module' => 'date',
    'columns' => 
    array (
      'value' => 
      array (
        'type' => 'varchar',
        'length' => 20,
        'not null' => false,
        'sortable' => true,
        'views' => true,
      ),
      'value2' => 
      array (
        'type' => 'varchar',
        'length' => 20,
        'not null' => false,
        'sortable' => true,
        'views' => false,
      ),
      'rrule' => 
      array (
        'type' => 'text',
        'not null' => false,
        'sortable' => false,
        'views' => false,
      ),
    ),
    'display_settings' => 
    array (
      'label' => 
      array (
        'format' => 'above',
        'exclude' => 0,
      ),
      5 => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      'teaser' => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      'full' => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      4 => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      2 => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      3 => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      'token' => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
    ),
  ),
);

However, when I select this cck date field as a field in a view (using "from" date only and labled "Date"), and set the view Style to "Table", when I click on Style settings, the date column does not display a sortable checkbox.

Anything I can do about this?

For the record, I'm not complaining about the module at all. I'm just trying to see if I can find a solution to this particular problem. I could simply be overlooking something quite obvious.

merlinofchaos’s picture

Ahh. That's probably an issue for date.module then, if for some reason the date field isn't set click sortable. The 'complaining' comments were directed at the other poster, not you. I was simply correcting you about date fields not being sortable. =)

Doomd’s picture

Do you happen to know if this problem is indeed fixed in Drupal 7?

I've got another site coming up in a few months that could utilize this functionality.

Thanks!

nealb13’s picture

Has anyone figured this out yet?

ikeigenwijs’s picture

same problem
I have a lot of fields not registered as sortable. And all containing text of some sort.
how to fix this?

Is it related that i use relationships?
thx in advance,

Byfred’s picture

[ISSUE FIXED]

To sort user profiles by date, follow those steps:

1) Download and install Content Profile module;
2) Download and install CCK module;
3) Download and install Date module;
4) Create a content type Profile, create a CCK field type Date;
5) Go to Content Type page and edit "Profile", check the option "Use this content type as a content profile for users"
6) Go to view's edit panel, add a relationship node: Content profile, select Profile you've created;

Now you can select date in sort panel.