Page 1 of 1

Mantis 2.0.0-c8fe307 - sorting by numeric custom field

Posted: 18 Aug 2016, 16:56
by Chris_Z
Hi,

First of all, I would rather report this to your Bug Tracker, but sign up is disabled there so it is a Catch-22. Maybe some admin can help?

It seems that sorting order is rather alphanumeric (by character values) instead of numeric (by stored values) when sorting Issues by Custom Field of type Numeric.
See the TRAC column in the attached screenshot:
Custom Field sorting order bug
Custom Field sorting order bug
Snapshot-2016-08-18-174818.png (44.89 KiB) Viewed 5094 times
Cheers,
/Chris

Re: Mantis 2.0.0-c8fe307 - sorting by numeric custom field

Posted: 18 Aug 2016, 21:49
by atrol
Chris_Z wrote: Maybe some admin can help?
I created account Chris_Z for you. You should get email to activate your account.

See https://www.mantisbt.org/bugs/view.php?id=6872 and related issue for a workaround that works with MySQL

Re: Mantis 2.0.0-c8fe307 - sorting by numeric custom field

Posted: 18 Aug 2016, 22:46
by Chris_Z
Thank's a lot for your assistance.
(and BTW, I didn't realize that this particular sorting problem was that long in teeth :lol: )

Best!

Edit - FYI: for v2.0.0 (build c8fe305) the patch should be applied in file: filter_api.php, function: filter_get_query_sort_data() as follows:

if ( CUSTOM_FIELD_TYPE_NUMERIC == custom_field_type ( $t_custom_field_id ) ) {
$c_cf_alias = "CAST($t_cf_table_alias.value AS UNSIGNED)";
}

Code: Select all

			# if sorting by a custom field
			if( strpos( $c_sort, 'custom_' ) === 0 ) {
                           
            ....

				# check to be sure this field wasn't already added to the query.
				if( !in_array( $t_cf_select, $p_query_clauses['select'] ) ) {
					$p_query_clauses['select'][] = $t_cf_select;
					$p_query_clauses['join'][] = 'LEFT JOIN {custom_field_string} ' . $t_cf_table_alias . ' ON
										{bug}.id = ' . $t_cf_table_alias . '.bug_id AND ' . $t_cf_table_alias . '.field_id = ' . $t_custom_field_id;
				}

				# This override works for MySQL only.
				# Enforce correct sorting order of Numeric Custom Fields (BUG 9120 workaround)
				# see: https://www.mantisbt.org/bugs/view.php?id=9120
				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