Expand my Community achievements bar.

SOLVED

Add custom Order By option in Core List component

Avatar

Level 4

Hello All,

 

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

supriyahande_0-1698816086117.png

 

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?  


1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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/w... 

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

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

 

Still, if you find any trouble let me know.

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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/w... 

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

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

 

Still, if you find any trouble let me know.

Avatar

Community Advisor

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

Avatar

Administrator

@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