View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update | 
|---|---|---|---|---|---|
| 0009120 | mantisbt | custom fields | public | 2008-05-02 16:56 | 2018-04-12 07:38 | 
| Reporter | bfoddy | Assigned To | atrol | ||
| Priority | normal | Severity | minor | Reproducibility | always | 
| Status | closed | Resolution | fixed | ||
| Product Version | 1.1.1 | ||||
| Fixed in Version | 2.7.0 | ||||
| Summary | 0009120: 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 ( 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. | ||||
| Tags | No 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
 | ||||
| Clarification: | |
| Did I get it right, you have some "1|2|3..." defined in you custom field? 
 | |
| 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. | |
| 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) | |
| Ok, thanks for testing this. I haven't tried it myself yet. Its a minor issue, but perhaps one that others will encounter. | |
| 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 :-( | |
| can anyone fix this? there has been no movement in here since a month... THANK YOU! | |
| Please fix this. I need natural sorting very much 0013787 | |
| I also need this to work with values of type "numeric" and would appreciate a patch | |
| Could anyone look into this issue? We would be very greatful. | |
| This bug is reproducible in Mantis-1.2.15. I created a numeric custom field and sorting doesn't work in View Issues page. | |
| 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. | |
| For information, the functionnality has been added and tested OK in 1.2.19. | |
| 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? | |
| Since we updated to MantisBT 2.12.0, these custom fields are sorting properly. | |
| Thanks for telling. | |
