Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.3
Component:
fieldapi data
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
18 Jun 2012 at 18:29 UTC
Updated:
3 Jul 2012 at 05:11 UTC
I have a custom field declared and I am trying to make it sortable. The field holds date values already formatted ie: 06/10/12. How could I make this sortable? I thought this code would work but the header on the table doesn't become hyper linked even.
function uc_order_views_data() {
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
}
I do have the ability to send through a UNIX epoch timestamp instead if that would help me make this sortable so long as I can sort by the epoch but render it as a formatted date.
**The fact that this is an extension of ubercart bears no factor on the result. Treat this question as if it were just a simple implementation of the views module, which in essence it is.**
Comments
Comment #1
diggingrelic commentedI am putting a bounty on this issue, you can bid the amount you want to be paid to solve this issue at:
http://cofundos.org/project.php?id=115605
Comment #2
merlinofchaos commentedThe handler you use must implement the click_sort() method which is what actually implements the sorting. I don't know anything about the uc_order handlers. Typically the default click_sort() handler is all you need.
The default implementation is here:
http://api.drupal.org/api/views/handlers%21views_handler_field.inc/funct...
If that handler doesn't implement the method you'll need to extend that handler.
It's also possible that the uc handler overrides the default implementation of click_sortable:
http://api.drupal.org/api/views/handlers%21views_handler_field.inc/funct...
Comment #3
diggingrelic commentedThank you for your comments merlinofchaos. I very much appreciate them. This should be enough information for me to figure this out.
Comment #4
diggingrelic commentedWell, I have it working, I didn't realize that
'click sortable' => TRUEjust exposes the field to the UI sort radio button on the view settings. So, once I checked that it works as expected, almost.My handler extends views_handler_field_date
The data is not a time stamp and is already in Date format: 06/20/2012
It is not sorting properly. It is sorting like a string from left to right. How can I have it sort it as a date?
Comment #5
diggingrelic commentedComment #6
diggingrelic commentedOkay, so I learned what the issue is with sorting a formatted date, it doesn't work unless you go YYYY-MM-DD. However, I decided to convert the data to unix time stamps and then use the standard views_handler_sort_date stuff. So, it is working.