View Issue Details

IDProjectCategoryView StatusLast Update
0006872mantisbtcustom fieldspublic2017-10-08 23:52
Reporterstb Assigned Tocproensa  
Status closedResolutionfixed 
Product Version1.0.1 
Target Version2.7.0Fixed in Version2.7.0 
Summary0006872: Sort of custom fields does not use data type

I added a custom field to view_all_bug_page.php using custom_function_inc.php. The field is a "number" field (long integer) but is stored internally as string in mantis/mysql. If I click on the column header of this custom field the view gets sorted alphabetically (not numerically).

Mantis should look at the specified data type and do numeric sort instead of pure text sort.

I know mantis will support "real" numeric data types (storing real numbers in mysql database) in the future. But I think this should be fixed regardless of that feature. I personally see some advantages storing custom field values as string.

TagsNo tags attached.


related to 0009120 closedatrol Numeric Custom fields on View All don't sort correctly 
related to 0023265 closedcproensa Filter selection for numeric custom fields aren't sorted correctly on distinct values list 
child of 0023443 closedcproensa Fixes related to custom fields on filters, columns and visibility 




2006-04-05 11:21

reporter   ~0012466

I've got the same exact problem, ¿could you solve it? I'd appreciate any help you can give me.
Regards from Argentina...




2006-04-05 13:56

reporter   ~0012468

Last edited: 2017-09-26 03:16

View 2 revisions

Ok, here's a workaround which should work in most cases (at least in showing those bug lists). Only integer values will be sorted correctly and there's no warranty this will work. There might be errors if you have stored non-integers! Use at your own risk.

Add the following lines into filter_api.php:

(for my installation this is around line 837)

if(custom_field_type($t_custom_field_id) == 1)
  $c_sort = "CAST($c_sort AS UNSIGNED)";

Those 4 lines should be added after the line:
$c_sort = "$t_custom_field_string_table.value";
and before the line:
$t_select_clauses[] = $t_custom_field_string_table.value";



2006-04-05 15:59

reporter   ~0012470

thanks a lot for your quick answer IT WORKED MORE THAN GREAT!
I was trying something similiar but in the wrong file (view_all_set.php)



2017-09-25 17:26

reporter   ~0057815

I don't think this is very minor as indicated here. It's a bug that needs to get fixed sooner than later. On MantisHub I had to add a regular expression to suppress leading zeroes and users now have to enter leading zeroes to sort correctly. If a type is numeric and it does not sort according to the actual value, that's a major bug.



2017-09-27 07:36

developer   ~0057823


The fixes are included in this pull request:
Maybe you could try that, feedback and testing is always welcomed.


Related Changesets

MantisBT: master dc68e440

2017-08-25 20:03:15


Committer: dregad Details Diff
Fix sorting for number based custom fields

For types numeric, float, and dates
- Make nulls appear last in the ordered result.
- Cast the values to sort them numerically.

Fixes: 0023260, 0006872
Affected Issues
0006872, 0023260
mod - core/filter_api.php Diff File

Issue History

Date Modified Username Field Change
2006-03-20 05:38 stb New Issue
2006-04-05 11:21 stello Note Added: 0012466
2006-04-05 13:56 stb Note Added: 0012468
2006-04-05 15:59 stello Note Added: 0012470
2013-12-10 03:34 atrol Relationship added related to 0009120
2017-08-26 13:11 cproensa Relationship added related to 0023265
2017-08-26 13:12 cproensa Category customization => custom fields
2017-08-26 13:13 cproensa Status new => assigned
2017-08-26 13:13 cproensa Assigned To => cproensa
2017-09-25 17:26 ShapiroCloud Note Added: 0057815
2017-09-26 03:16 dregad Note Edited: 0012468 View Revisions
2017-09-27 07:36 cproensa Note Added: 0057823
2017-10-07 12:45 dregad Changeset attached => MantisBT master dc68e440
2017-10-07 12:45 cproensa Status assigned => resolved
2017-10-07 12:45 cproensa Resolution open => fixed
2017-10-07 12:45 cproensa Fixed in Version => 2.7.0
2017-10-07 13:34 atrol Target Version => 2.7.0
2017-10-08 11:49 cproensa Relationship added child of 0023443
2017-10-08 23:52 vboctor Status resolved => closed