Feature Request: Natural Sort

le_petit_basil - November 18, 2008 - 19:21
Project:Views Custom Field
Version:6.x-1.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Views Custom Field Rocks. But it would be even better if it were possible to sort on Custom Fields.

#1

casey - November 19, 2008 - 13:56

It uses PHP afterwards to generate row-specific text so its currently not possible.

Could you give some examples how you like to use it? Sort on what?

#2

ipto - November 20, 2008 - 09:37
Version:5.x-1.0-beta1» 6.x-1.x-dev

For example have values row: 8 / 2, 10 / 5, 8 / 7, 3.4 / 2, 8 / 6 (before '/' - average fivestar value, after - voting user count), you need to sort this value as a string:

10/5
8/7
8/6
8/2
3.4/2

To do this, I glued them into one customfield field, but only now noticed that sort of pressing header in the table does not.

In views theming filles (\modules\views\theme\) I have full access to all views fields table, and just merge (or do other activities with them) they is not difficult without customfield :

          <td class="views-field views-field-voting_value">
            <?=((!empty($row[value]) && is_numeric($row[value])) ? (round($row[value]/10, 2)) : '&nbsp;')?>
            <?=(!empty($row[value_1]) ? '/' . $row[value_1] : '&nbsp;')?>
          </td>

#3

casey - November 20, 2008 - 12:46

You already can do this. Just add two sorts to your view; first on "average fivestar value" second on "voting user count".

Let me know if that's what you're looking for.

#4

ipto - November 20, 2008 - 17:15

Yes, ask if the criteria for grading in block vies, all appear as you want, but when you click on the header field tables default sorting break and starts sorting the field corresponding pressed headline, that is why I combine two fields (value_average and value_count) in one

#5

casey - December 13, 2008 - 17:00

I could introduce a new customfield "fieldcombination" which combines two or more fields in the query; then it would be possible to sort on those fields.

But currently I don't have much time; I'll look into it next week.

#6

casey - February 27, 2009 - 15:06
Status:active» postponed

Sorry don't have time for this on the moment.

#7

asak - March 24, 2009 - 12:49

I'm using CustomField to calculate some user info, which results in a single or double digit number (e.g 1 or 3 or 24) - how can i get views to enable sorting by this results?

#8

casey - March 24, 2009 - 13:21

You can't, as customfields are evaluated after querying of the (sorted) result.

I have however some ideas to introduce some fields that allows to add calculations (or other sql functions) to a views query. Unfortunatly I don't have very much time right now; so it can take some time before this is implemented.

#9

emagus - May 13, 2009 - 22:33

Hey casey.

First of all: Thanks for your great module.
Reading this, i get the feeling this isn't gonna happen too soon, which i totally understand. It's a rather critical feature for me (and possibly many others). So it would be really nice if you could share your aforementioned ideas with us. Maybe someone who really needs this too and who is an experienced drupal developer is able to implement your ideas. And maybe, if i feel like it's easy enough for me, I will even try this myself (even though i'm very low skill on php and new to drupal development).

thanx in advance

#10

kratib - May 22, 2009 - 21:59

I use this module all the time, thanks for a great contribution.

Attached is a patch to provide sorting for PHP Code custom fields. I'd be happy if people here could use it and validate it, and if the module maintainer would consider committing it in. Since I need this for my professional (commercial) work, I'm willing to provide support for it. If it works well, I can extend this to Row Number field as well (I guess it doesn't make sense for Markup).

To activate sorting, just choose a sorting method in the field's settings. Make sure the fields in the Table style settings are marked as sortable.

AttachmentSize
views_customfield.sorting.patch 5.74 KB

#11

casey - May 24, 2009 - 15:07

@kratib For about a month I don't have time to work on my drupal modules. I could give you CVS access?

#12

kratib - May 24, 2009 - 16:57
Status:postponed» needs review

@casey thanks for our offer. Go ahead and grant me CVS access. In any case I will wait to hear from people who tried the patch before committing it.

Did you get a chance to try the patch?

#13

casey - May 24, 2009 - 17:46

CVS access granted.

No, don't have time for anything at all (working on a paper for my study with a short deadline and after that a couple of exams).

I was actually also working on a solution for this. My idea was to allow the usage of views sort handlers as clicksorts (configurable per custom field). Don't have it fully working yet though.

#14

kratib - May 25, 2009 - 00:02

Right now my patch is just for the field handler to be click sortable. I don't know what it takes to write a sort handler, so I'll wait for people to tell me which one they need.

#15

emagus - May 26, 2009 - 15:11

@kratib: Tested the patch and works perfectly fine so far for me! Thank you so much!!! Great job!
@casey: Thank you for giving kratib cvs access. That's true open source spirit! And also thanx for checking your issue queue despite your school stress!

#16

kratib - June 15, 2009 - 06:21
Status:needs review» active

I just committed the above patch (tweaked for performance) to the latest dev release. I tested it on a view with 10K nodes so things look alright to me. Note that this applies to PHP custom field only, not Rownumber yet.

I'll keep this active until I commit a similar patch for Rownumber, which will probably require refactoring some code to a common ancestor of these two classes to avoid code duplication.

#17

kratib - July 4, 2009 - 05:15

FYI: I just found a bug that happens when the PHP code generates HTML to be rendered. I committed a fix to the latest dev.

#18

arielon - July 14, 2009 - 17:53

Well, this last commit would be great for me if it would work. I've tried with all sorting types and nothing.

I'm trying to show the user's first + last name, eg:

<?php

echo '<a href="profile/' .
strtolower(str_replace(" ", "-",
$data->node_data_field_location_field_name_value . "_"
. $data->node_data_field_location_field_surname_value)) . '"'
. ' rel="lightframe[|width:670px; height:490px;]">'
. $data->node_data_field_location_field_name_value . ", "
. $data->node_data_field_location_field_surname_value
. '</a>';
?>

(tried also with simpler versions)

The output is correct, but I just can't sort... The column title doesn't appear as a link..

Any help appreciated.

#19

kratib - July 14, 2009 - 18:13

If you're using table output, then you need to open the table settings and set this field as sortable. Does that apply?

#20

arielon - July 14, 2009 - 19:05

Oh yes! Forgot that... Thank you for the quick answer!

Great job.

#21

markus_petrux - July 16, 2009 - 07:35

@kratib: Could you please add a note in the description of the sorting option to describe a little that sorting will load all records of the query in memory to resolve the sort? Please. On my installation there is staff that can create views and I have given this module to them, but they may try to against thousands of records.

I would even ask for an option to disable sorting for PHP fields, or maybe if there was a PHP field sortable, and another one that is not sortable, then we could use the later so that users cannot take the site down when creating and then running a view against a huge number of records.

Other than that, nicely done. ;-)

Thanks

#22

kratib - July 16, 2009 - 16:22

@markus_petrux: I added the warning note as a description to the field. It is easy to set the sorting option to none (which it is by default). Also, sorting in memory won't occur until the header of the custom field is actually clicked.

#23

markus_petrux - July 16, 2009 - 16:48

Thank you. This will save me one or two headaches.

#24

tengoku - October 21, 2009 - 23:45

hi.... thanks for the patch... it works on table outputs.... sadly i use de grid output.. and don't works.... u have to do something special to this??

#25

kratib - October 22, 2009 - 02:14

The implemented feature is only for tables so far. To make it work for other styles, one has to implement sort handlers which is still not done. You can open a new feature request for it if you wish.

 
 

Drupal is a registered trademark of Dries Buytaert.