View Issue Details

IDProjectCategoryView StatusLast Update
0009120mantisbtcustom fieldspublic2018-04-12 07:38
Reporterbfoddy Assigned Toatrol  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.1.1 
Fixed in Version2.7.0 
Summary0009120: Numeric Custom fields on View All don't sort correctly
Description

I have a numberic custom field, (EstHrs) that I have added to all my projects. I have also added this field to the View_all page via a custom configuration of:

All Users All Projects view_issues_page_columns complex

array (
0 => 'selection',
1 => 'edit',
2 => 'priority',
3 => 'id',
4 => 'sponsorship_total',
5 => 'bugnotes_count',
6 => 'attachment',
7 => 'category',
8 => 'severity',
9 => 'status',
10 => 'last_updated',
11 => 'custom_EstHrs',
12 => 'summary',
)

This works great except when the custom field is selected to sort on, it sorts by a character order, not numeric values, so 2 will sort before 10.

TagsNo tags attached.
Attached Files
custom_sort_numeric.patch (627 bytes)   
--- mantisbt-1.2.15/core/filter_api.php.orig	2014-01-22 11:50:42.315646273 +0100
+++ mantisbt-1.2.15/core/filter_api.php	2014-01-22 11:53:43.055395935 +0100
@@ -933,6 +933,9 @@
 					$p_query_clauses['join'][] = "LEFT JOIN $t_custom_field_string_table $t_cf_table_alias ON $t_bug_table.id = $t_cf_table_alias.bug_id AND $t_cf_table_alias.field_id = $t_custom_field_id";
 				}
 
+				if( CUSTOM_FIELD_TYPE_NUMERIC == custom_field_type( $t_custom_field_id ) ) {
+					$c_cf_alias = "CAST($t_cf_table_alias.value AS UNSIGNED)";
+				}
 				$p_query_clauses['order'][] = "$c_cf_alias $c_dir";
 
 			# if sorting by plugin columns
custom_sort_numeric.patch (627 bytes)   

Relationships

has duplicate 0013787 closedatrol Wrong sort by custom field column 
related to 0006872 closedcproensa Sort of custom fields does not use data type 

Activities

bfoddy

bfoddy

2008-05-02 17:26

reporter   ~0017738

Clarification:
The custom field is defined as an Enumeration with integer values possible.

polzin

polzin

2008-07-01 11:45

reporter   ~0018262

Did I get it right, you have some "1|2|3..." defined in you custom field?

  1. Why not use custom field type "numeric"?
  2. Why not write " 1| 2|...| 9|10"... this should sort correctly.
bfoddy

bfoddy

2008-07-01 11:58

reporter   ~0018263

I didn't use numerics because we wanted a limited set of possible values the Enumeration provided. The space fill values idea however is sufficient.

We can close this issue.

Structed

Structed

2008-07-02 09:46

reporter   ~0018280

Last edited: 2008-07-02 09:49

Or you could introduce a option field to select the sort function for an enumeration type - natural or normal sort.

I do not get a sufficient result with an enumeration field and values with spaces before the actual numbers (with values between 0 and 100, step 10)

bfoddy

bfoddy

2008-07-02 17:13

reporter   ~0018283

Ok, thanks for testing this. I haven't tried it myself yet. Its a minor issue, but perhaps one that others will encounter.

Structed

Structed

2008-07-03 10:41

reporter   ~0018289

Last edited: 2008-07-03 10:42

yes, but nevertheless it is pretty annoying. especially if this is needed very much. what makes it even worse, i have no time to patch it myself :-(

Structed

Structed

2008-08-14 03:22

reporter   ~0019154

can anyone fix this? there has been no movement in here since a month... THANK YOU!

psylosss

psylosss

2012-01-22 06:41

reporter   ~0030993

Please fix this. I need natural sorting very much 0013787

markusobrist

markusobrist

2012-07-25 10:15

reporter   ~0032366

I also need this to work with values of type "numeric" and would appreciate a patch

markusobrist

markusobrist

2013-08-12 13:12

reporter   ~0037656

Could anyone look into this issue? We would be very greatful.

libregeek

libregeek

2013-12-10 00:51

reporter   ~0038838

This bug is reproducible in Mantis-1.2.15.

I created a numeric custom field and sorting doesn't work in View Issues page.

tporadowski

tporadowski

2014-01-22 06:06

reporter   ~0039136

For anyone interested in adding this functionality to 1.2.15 (using MySQL) - you can patch your code with "custom_sort_numeric.patch". Please note that a more generic and DB-aware solution would have to be implemented to support other databases.

mantisiator

mantisiator

2016-08-29 09:05

reporter   ~0053906

For information, the functionnality has been added and tested OK in 1.2.19.
Thanks a lot

timlonggr

timlonggr

2018-03-14 08:48

reporter   ~0059204

This is still an issue for me with Mantis 2.5.1 using a numeric custom field. I am using MySQL, so would be above patch work for me? If so, how would I install it?

timlonggr

timlonggr

2018-04-11 09:46

reporter   ~0059530

Since we updated to MantisBT 2.12.0, these custom fields are sorting properly.

atrol

atrol

2018-04-11 09:53

developer   ~0059531

Thanks for telling.
This was fixed in 2.7.0 when 0006872 was fixed.