Add custom Order By option in Core List component | Community
Skip to main content
supriya-hande
Level 4
November 1, 2023
Solved

Add custom Order By option in Core List component

  • November 1, 2023
  • 3 replies
  • 945 views

Hello All,

 

There is a requirement to add custom sort order date option in Core List v3 component as below.

 

Also we want this core List component should be restricted to fetch only Article and Article category templates. I know I need to extend core list component but I am unsure the way how to implement this. Do I need to re-write logic of core List component(java code) to fetch only article/article-category pages based on which kind of list we want like Fixed list or Child page or Tags and on top of that sort it by different option like custom sort oder or title or list modified? In this case I need to re-write all logic of core List interface. Is there any other way to achieve this?  


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

Hello @supriya-hande ,

For your requirement, the best practice is using Sling Delegation Pattern where you need to change the logic of "Options for Child Pages" in your Java implementation class.

The core list implementation: https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v3/ListImpl.java 

Sling Delegation Pattern Doc: https://medium.com/@veena.vikraman19/aem-avoiding-delegation-pattern-pitfalls-with-core-components-973c93a59fc7 

Example: https://github.com/Sady-Rifat/aem-demo/commit/7047cd9dcb6601359f61d13b373da552272ca8cc 

 

Still, if you find any trouble let me know.

3 replies

Sady_Rifat
Community Advisor
Sady_RifatCommunity AdvisorAccepted solution
Community Advisor
November 1, 2023

Hello @supriya-hande ,

For your requirement, the best practice is using Sling Delegation Pattern where you need to change the logic of "Options for Child Pages" in your Java implementation class.

The core list implementation: https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v3/ListImpl.java 

Sling Delegation Pattern Doc: https://medium.com/@veena.vikraman19/aem-avoiding-delegation-pattern-pitfalls-with-core-components-973c93a59fc7 

Example: https://github.com/Sady-Rifat/aem-demo/commit/7047cd9dcb6601359f61d13b373da552272ca8cc 

 

Still, if you find any trouble let me know.

aanchal-sikka
Community Advisor
Community Advisor
November 1, 2023

Hello @supriya-hande 

 

Please use the Delegation pattern as suggest by @sady_rifat . That will help us customize only whats needed.

You might still have to copy some code, which stays the same but will still be able to avoid plenty.

 

Regarding filtering:

  • In the ListImpl, there is getPages(), which getStaticListItems()/getChildListItems() etc based on the type of List you are rendering.
  • These in turn use specific functions for filtering, like getChildListItems() uses collectChildren()
  • You can customize only related functions and achieve the desired results.

 

Regarding Sorting:

- Sorting is done after filtering, in same getPages()

You can add more sort criterions and extend accordingly

 

Aanchal Sikka
kautuk_sahni
Community Manager
Community Manager
November 1, 2023

@supriya-hande Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni