Posted by alleyhector on January 15, 2013 at 11:03pm
I have a view in table format and want to use the "sortable" feature under the format settings but only the title has the "sortable" button available. After much searching it seems that perhaps this is because I used custom fields. However they're just text lists. Is there really not a simple way to do this? Is there a module that can help me? A simple code workaround?
Help is much appreciated.
Comments
What do you mean by "custom
What do you mean by "custom fields"? Those can be sortable if they have an appropriate sort handler.
Do you mean that each field contains a list? It's not clear how to sort a list of lists.
The thing to remember is that the standard Views aggregation, grouping, filtering, and sorting is all handled in the database by running SQL. This all generates a query with an ORDER BY on the field (or an alias) in the database. Can your field be sorted that way?
In any case, have a look at hook_views_data(). The field definition needs
'click sortable' => TRUE for the sortable thing to be available when configuring a table.--
www.ztwistbooks.com. Math books that are actually fun.
By custom I just meant that
By custom I just meant that they were content types I created in /admin/structure/types as "list (text)" field types. Is that what you're asking?
How do I change the sort handler for those?
You change the sort handler
You change the sort handler with an implementation of hook_views_data_alter().
The sort handler (if any) is initially set via hook_views_data(). However, this gets into some fairly deep voodoo. That is probably established automatically somewhere, and I'm afraid that I'm not up to tracing that code right now.
I'll give you this, though. The field handler is probably views_handler_field_prerender_list(). Maybe.
--
www.ztwistbooks.com. Math books that are actually fun.