How to sort issues by 3 fields in View Issues Page - Urgent

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
mhsieh
Posts: 1
Joined: 18 Jun 2008, 11:32

How to sort issues by 3 fields in View Issues Page - Urgent

Post by mhsieh »

Hello Mantis Forums Users!

I'd like to sort issues by 3 different fields in View Issues Page; First sort by Priority, then by Status, then by Date Submitted. Is this possible and how to do it?

Thanks a lot!

Please help,
:D
vboctor
Site Admin
Posts: 1293
Joined: 13 Feb 2005, 22:11
Location: Redmond, Washington
Contact:

Re: How to sort issues by 3 fields in View Issues Page - Urgent

Post by vboctor »

If you go to advanced filters, you can sort by two fields. However, you can't sort by more than 2 fields.
Migrate your MantisBT to the MantisHub Cloud
philippd
Posts: 3
Joined: 23 Mar 2010, 11:25

Re: How to sort issues by 3 fields in View Issues Page - Urg

Post by philippd »

Hi,


I've got the same problem.
I'd like to sort by three cols

Is there any way to reach this? maybe with a plugin or some dirty code added somewhere or is this limited by the database?


Thanks a lot in advance
Philipp
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: How to sort issues by 3 fields in View Issues Page - Urg

Post by atrol »

AFAIK there is no plugin for it
You would have to change the code of functions in file core/filter_api.php
Start looking at print_filter_show_sort()
Please use Search before posting and read the Manual
shiroamada
Posts: 1
Joined: 16 Oct 2012, 02:55

Re: How to sort issues by 3 fields in View Issues Page - Urg

Post by shiroamada »

core/filter_api.php

Change < 2 to < 3, got 2 places to make the changes.

Code: Select all

$t_sort_fields = explode( ',', $t_filter[FILTER_PROPERTY_SORT_FIELD_NAME] );        
$t_dir_fields = explode( ',', $t_filter[FILTER_PROPERTY_SORT_DIRECTION] );

for( $i = 0;$i < 3;$i++ ) {
Look for this function print_filter_show_sort()
add this line after array[1]

Code: Select all

if( !isset( $t_sort_fields[2] ) ) {
	$t_sort_fields[2] = '';
	$t_dir_fields[2] = '';
}
and also this

Code: Select all

        echo ', ';
        
        # for third sort
		echo '<select name="', FILTER_PROPERTY_SORT_FIELD_NAME, '_2">';
		foreach( $t_shown_fields as $key => $val ) {
			echo '<option value="' . $key . '"';
			check_selected( $key, $t_sort_fields[2] );
			echo '>' . $val . '</option>';
		}
		echo '</select>';
		echo '<select name="', FILTER_PROPERTY_SORT_DIRECTION, '_2">';
		foreach( $t_shown_dirs as $key => $val ) {
			echo '<option value="' . $key . '"';
			check_selected( $key, $t_dir_fields[2] );
			echo '>' . $val . '</option>';
		}
		echo '</select>';
After the else statement as well.

Code: Select all

 echo '<input type="hidden" name="', FILTER_PROPERTY_SORT_FIELD_NAME, '_2" value="last_updated" />';
		echo '<input type="hidden" name="', FILTER_PROPERTY_SORT_DIRECTION, '_2" value="DESC" />';

view_all_set.php
add another 2 extra variable

Code: Select all

$f_sort_2				= gpc_get_string( FILTER_PROPERTY_SORT_FIELD_NAME . '_2', 'summary' );
$f_dir_2				= gpc_get_string( FILTER_PROPERTY_SORT_DIRECTION . '_2', 'ASC' );
and also this.

Code: Select all

	$f_sort = ( ( $f_sort_d != "" ) ? $f_sort_d : $f_sort_0 ) . ( ( $f_sort_1 != "" ) ? "," . $f_sort_1 : "" ) . ( ( $f_sort_2 != "" ) ? "," . $f_sort_2 : "" );
	$f_dir = ( ( $f_dir_d != "" ) ? $f_dir_d : $f_dir_0 ) . ( ( $f_dir_1 != "" ) ? "," . $f_dir_1 : "" ) . ( ( $f_dir_2 != "" ) ? "," . $f_dir_2 : "" );
I manage to change this, and I got 3 sorting options :)
Adysone
Posts: 1
Joined: 21 Aug 2015, 13:20

Re: How to sort issues by 3 fields in View Issues Page - Urg

Post by Adysone »

3 years later, it's always efficient, thank you shiroamada!
Post Reply