Jump to content

Pages > "Sort By" dropdown entries


Carl Maltby

Recommended Posts

Hi everyone,

This is somewhat of a bothersome thing. The Sort By dropdown in the listing pages has far too many options. The categoryTable template (where this is generated) doesn't seem to hold any immediate answers as to whether the sort options are even filtered.

For example, our Tutorials section displays the following Sort By options:

  • Last Reply
  • Title
  • Start Date
  • Most Commented
  • Most Viewed
  • sort_record_last_comment
  • sort_record_comments
  • sort_record_views
  • Title
  • sort_record_publish_date
  • Tutorial Header Image
  • Difficulty
  • Creative Commons Licencing
  • Creative Commons Licencing Attribution
  • Teaser
  • Custom

Clearly this looks ridiculous and shoddy to the end user. Do we need to manually specify sort options in the HTML template (categoryTable) or is there a more graceful way of doing this in the ACP?

http://www.projectguitar.com/tutorials/instrument-building/

TIA

Link to comment
Share on other sites

There is no way around this currently, but there was a feature request about this months ago. It should just be an option in the field settings, so fields can be turned off for sorting. 
And in addition it needs a way to deal with ASC or DESC direction either on the admin or user side. For some fields the resulting ordering just doesn’t make any sense. 

Link to comment
Share on other sites

19 minutes ago, opentype said:

There is no way to around this currently, but there was a feature request about this months ago. It should just be an option in the field settings, so fields can be turned off for sorting. 
And in addition it needs a way to deal with ASC or DESC direction either on the admin or user side. For some fields the resulting ordering just doesn’t make any sense. 

 

That's exactly what I was expecting somewhere in the ACP also. It shouldn't be too onerous to roll into the software, however I suspect that without any intervention modifying how settings are rendered through the templates, it is "semi-hardcoded" into Pages. I suspect that this bit of HTML Database Template code from will be a continuing bugbear (default, categoryTable):

			{{if isset( $table->sortOptions ) and !empty( $table->sortOptions )}}
				<li>
					<a href="#elSortByMenu_menu" id="elSortByMenu_{$table->uniqueId}" data-role='sortButton' data-ipsMenu data-ipsMenu-activeClass="ipsButtonRow_active" data-ipsMenu-selectable="radio">{lang="sort_by"} <i class="fa fa-caret-down"></i></a>
					<ul class="ipsMenu ipsMenu_auto ipsMenu_withStem ipsMenu_selectable ipsHide" id="elSortByMenu_{$table->uniqueId}_menu">
						{{$custom = TRUE;}}
						{{foreach $table->sortOptions as $k => $col}}
							<li class="ipsMenu_item {{if $col === $table->sortBy}}{{$custom = FALSE;}}ipsMenu_itemChecked{{endif}}" data-ipsMenuValue="{$col}" data-sortDirection='{{if $col == 'title'}}asc{{else}}desc{{endif}}'><a href="{$table->baseUrl->setQueryString( array( 'filter' => $table->filter, 'sortby' => $col, 'sortdirection' => ( $col == 'title' ) ? 'asc' : 'desc', 'page' => '1' ) )}">{lang="{$table->langPrefix}sort_{$k}"}</a></li>
						{{endforeach}}
						{{if $table->advancedSearch}}
							<li class="ipsMenu_item {{if $custom}}ipsMenu_itemChecked{{endif}}" data-noSelect="true">
								<a href='{$table->baseUrl->setQueryString( array( 'advancedSearchForm' => '1', 'filter' => $table->filter, 'sortby' => $table->sortBy, 'sortdirection' => $table->sortDirection ) )}' data-ipsDialog data-ipsDialog-title='{lang="custom_sort"}'>{lang="custom"}</a>
							</li>
						{{endif}}
					</ul>
				</li>
			{{endif}}

 

If needs be, this can simply be hard-coded however that's about as graceful as a brick.

 

-----

 

13 minutes ago, chilihead said:

Looks like some missing language too.

 

Possibly. I asked a while back about a separate database field ($num_views) since it has been made (from what I am aware) read-only since 3.x; the problem was that we couldn't transfer a record from one database to another and manually set the value of $num_views to reflect view counts from the previous database. I don't normally need to touch language strings, however I suspect that fields like this which are not usually "public facing" don't have language strings associate with them? Nice to see that internal information strings are automagically leaking out.

Link to comment
Share on other sites

A while back I made a workaround for this problem. First, find the template where the filter menu is generated (for me it was Database Templates -> Record Listing -> categoryTable). Add the keys of the fields you want to have filtered to an array like this:

 

{{$allowed_sorts = array();}}
{{$allowed_sorts[] = "title";}}
{{$allowed_sorts[] = "rating";}}

{{$allowed_sorts[] = "field_22";}}

I put this right at the top of the template.

Then, find this loop in the template:

{{foreach $table->sortOptions as $k => $col}}
	<!-- Some html inserting each menu item -->
{{endforeach}}

and change it to this:

{{foreach $table->sortOptions as $k => $col}}
  {{if array_search( $k, $allowed_sorts )!==FALSE }}
	<!-- Some html inserting each menu item -->
  {{endif}}
{{endforeach}}

This is not a very pretty solution. If you add a new field later, you'll have to come back to this template and add the field key to the allowed_sorts array. But it will probably work until IPS adds this feature.

Link to comment
Share on other sites

  • 3 months later...

Has this issue been fixed in a new release? I have a custom page, database and fields and when I go to sort the page I have at 20 items to choose from. I want to eliminate all the default IPS items like Most Commented, Most Reviewed, Most Viewed, etc. Is there a way to do this in the Admin CP?

@snugRugBug thanks for the workaround on this. I appreciate your contributions.

Link to comment
Share on other sites

51 minutes ago, Action_Builder said:

Has this issue been fixed in a new release? I have a custom page, database and fields and when I go to sort the page I have at 20 items to choose from. I want to eliminate all the default IPS items like Most Commented, Most Reviewed, Most Viewed, etc. Is there a way to do this in the Admin CP?

@snugRugBug thanks for the workaround on this. I appreciate your contributions.

Yes, this will be resolved with 4.1.9 .
We're running here the beta and you can see in our bugtracker that we don't have any duplicate items anymore https://invisionpower.com/4bugtrack/active-reports/

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...