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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | viewCCKDateFieldSortable.jpg | 67.37 KB | somebodysysop |
Comments
Comment #1
merlinofchaos commentedIt is neither an oversight nor a bug. The way the profile module stores dates is a serialized array,which is not sortable in sql.
Comment #2
Doomd commentedCan you suggest another simple way to have this data sortable by date?
Comment #3
karens commentedThere 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.
Comment #4
somebodysysop commentedFor 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:
The dates themselves are formatted in a way so that they would be easily sorted in sql:
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.
Comment #5
astridman commentedum, 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?
Comment #6
dawehnerIf 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.
Comment #7
somebodysysop commentedI'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.
Comment #8
merlinofchaos commentedSomebodySysop: 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.
Comment #9
somebodysysop commentedYou are right. I should have made myself more clear. An export of the cck date field I created does say it is sortable:
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.
Comment #10
merlinofchaos commentedAhh. 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. =)
Comment #11
Doomd commentedDo 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!
Comment #12
nealb13 commentedHas anyone figured this out yet?
Comment #13
ikeigenwijs commentedsame 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,
Comment #14
Byfred commented[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.