Currently, when webform submission data is displayed in a view, sorting by column results in a funny order for numbers. E.g. 1, 10, 2, 3, ... This is evidently since the data is presented as text rather than numbers. Is there a way to get it to sort numbers properly? I've tried the Views Natural Sort module, but without luck. I'm not sure if I didn't implement it properly or if it doesn't work with webform submission data, but think it's more likely the latter.
Thanks for all the great work on this module and its Views integration. This code is beyond my ability, but I hope someone else will know how to do it.
Comments
Comment #1
quicksketchHi @dankoB, thanks for reporting this issue. I think you're right on. The cause of the problem is likely that Webform stores all data as text rather than numeric values. I think it would be a very reasonable feature to include a "Sort as numeric", which could CAST() the value into a float or integer when doing a sort.
Comment #2
garyg CreditAttribution: garyg commentedIs this needed feature ever coming?
Is there a work around in the meantime.
I have a view that displays integers but the sort is messed up.
Comment #3
quicksketchThis particular feature isn't high on my list, but if contributions are made here to speed this along I'm happy to review them. As with most things, this isn't a large amount of code to implement, just finding the right code within Views to utilize.
Comment #4
DanChadwick CreditAttribution: DanChadwick commentedThe Views Natural Sort module, which I contributed to, works by inferring the type of data in the title of a node and converting it to a non-readable representation which sorts in the intended order. For example, it could sort:
-100
-10
0
1 partridge in a pear tree
2
$10
100 gnawing rodents
300.01
1,000
The apple
Banana
Le Cirque
El Kabong
An Orange
The best way to handle this would be to create a second data column in the submissions data table and make this available to views. Given the space involved, it would best be a sub module so the column could be added and removed at will.
If you just want to handle numbers, that would be easier, but the format needs to be normalized if you intend to do it in the database. It will also be very slow on large datasets because you'd be do it each time you execute the query.
Comment #5
garyg CreditAttribution: garyg commentedThis is my work around for now.
My application was simple enough I could just use this.
Comment #6
DanChadwick CreditAttribution: DanChadwick commentedChanging this to numeric sort, which I think is what is actually desired, and incorporating it into #2449871: Numeric comparison and sort of submitted data in views as I think sorting and filtering on numeric data should be done together.