Sorting of Custom Columns in SearchResults Page | Community
Skip to main content
New Participant
February 14, 2023

Sorting of Custom Columns in SearchResults Page

  • February 14, 2023
  • 1 reply
  • 1770 views

We have a requirement to sort custom columns in SearchResults Page, when we use filter option in sites console or global AEM Sites search. We have custom columns like Book Title, Book No, Book Author & Book Cost.

 

Request URL:

http://localhost:4502/mnt/overlay/granite/ui/content/shell/omnisearch/searchresults.html

 

We are getting values for all these custom columns in sorted order based on only one single property as follows:

 

Path: /apps/settings/cq/search/facets/sites/jcr:content/items/orderby

Property: Value

listOrder: 4

metaType: hidden

name: orderby

sling:resourceType: granite/ui/components/coral/foundation/form/hidden

value: jcr:content/cq:lastModified

 

We want to sort data on click of each header columns up/down arrow in ascending & descending order.

 

Please suggest the way to implement this particular requirement.

 

@arunpatidar @nirmal_jose @nitesh_kumar-1 @pulkit_jain_ @smacdonald2008 

@kiran_vedantam @ritesh_mittal @debal_das @lukasz-m  @joerghoh   

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

lukasz-m
New Participant
February 15, 2023

Hi @s-k-agarwal,

In general this should work OOTB at least for Search Results (omnisearch) view. Here are detailed instruction how custom column can be added on AEM 6.5. In my example I will add column that will display Description value from page properties that is represented by jcr:description property in repository.

  1. Add custom column, to search results list view. List of columns is stored under /libs/wcm/core/content/common/availablecolumns, so to add custom column this node has to be overlay. This is how it looks in my example the full path is /apps/wcm/core/content/common/availablecolumns/description
  2. Next we have to make sure that proper data will be displayed in each row. Row is represented by /libs/cq/gui/components/coral/admin/page/row/row.jsp, this has to be modified, overlay mechanism will be used. As a result new file will b created under /apps/cq/gui/components/coral/admin/page/row/row.jsp, I have added some code in it that will be responsible to read jcr:description property. I have added my custom code right after code that shows information about workflow, it's because my custom column will be ordered after Workflow column. It is important to keep order of column and code that provides value aligned.
  3. And that is all. Now Search results can be checked to confirm it is working as expected.

Result:

  1. Default order:
  2. ASC order:
  3. DESC order:

Once again I would remind that above will work only for Search Results view, in other views like Sites custom column will appear as well, because row.jsp is used in many places - however different views can have different mechanism for sorting. Please also keep in mind that Search Results works client side, and orders only currently visible results. In other words when additional chunk of results is loaded order has to be applied again. This is characteristic of this view. What you can see on Sites works a bit different because sorting is done on backend against full set of results not only the one that are visible.

New Participant
February 16, 2023

Hi @lukasz-m 

 

Thanks for your response.

 

For us, sorting is not working.

 

It would be very helpful if you could provide us the Java/JSP file name, where the related sorting logic is present. If we want to customize the sorting behavior, where we need to modify.

 

We have Custom columns based on some component level properties, not on jcr:content node.

 

If it is using any datasource/servlet, please provide us that as well.