cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to sort the enum values in backoffice?

Former Member
0 Likes
2,486

Hi,

My requirement is to sort the enum values in backoffice. I have one attribute in product model that type is enum type, for this field need to show sorting enum in drop down list. I tried to extended "DefaultEnumEditor" and overrided getAllValues(.. , ..) method and i have written sorting logic here. but how to override this class ?

Accepted Solutions (1)

Accepted Solutions (1)

former_member638520
Contributor

Hi,

You can try to create your own 'com.hybris.cockpitng.editor.defaultenum.EnumValueResolver' which will override the default one (de.hybris.platform.platformbackoffice.editors.yenum.PlatformEnumValueResolver) and it would sort values before returning them. Another option is creating your own editor which would extend: com.hybris.cockpitng.editor.defaultenum.DefaultEnumEditor Thanks to this you would have the full control over values, order etc. After creating your own editor don't forget about using it in cockpit-config.xml (for example: ) I would suggest to get familiarize with this document: https://help.hybris.com/6.4.0/hcd/8bd4c25286691014b3f9876ca5816926.html#loio8bd4c25286691014b3f9876c... There is clear description how to create your own editor and how to use it

Regards,

Lukasz

Former Member
0 Likes

Thank you for reply. Yes, I have followed 2nd approach and created com.hybris.cockpitng.editor.defaultenum.DefaultEnumEditor extended this class and override this method "getAllValues(final String valueType, final Object initialValue)" and implemented sorting logic here. this is defination.xml

my custom class: public class SortEnumImpl extends DefaultEnumEditor{ } but here not calling override class. Am I missing configuration here? Kindly help me here.

Thanks,

former_member638520
Contributor
0 Likes

Hi, You need to use your editor in *-config.xml. For example, for create-wizard you should add the following configuration:

 <wz:property qualifier="yourField" editor="com.hybris.full.path.to.your.CustomEditor">


Regards

Lukasz

Former Member
0 Likes

thanks a lot. its working. Here the sorting should be apply sorting all the enum. I have created definition.xml and configured id in "MapPropertyExtender"

 definition.xml :
 
 <editor-definition id="org.training.sortenum"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/editor-definition.xsd">
 
     <type>java.lang.Enum(?:\((.*)\))?</type>
     <editorClassName>org.training.sortenum.SortEnumImpl</editorClassName>
 </editor-definition>

I configure the enum Id :

  <bean class="com.hybris.cockpitng.core.util.impl.MapPropertyExtender"
               lazy-init="false" init-method="extend" destroy-method="clean">
             <property name="additionalProperties">
                 <map merge="true" key-type="java.lang.String" value-type="java.lang.String">
     <entry key="java.lang.Enum(?:\((.*)\))?" value="org.training.sortenum"/>
                 </map>
             </property>
       </bean>

ighoneim
Explorer
0 Likes

MapPropertyExtender is deprecated since 6.4 and removed since 6.7, use corresponding class from com.hybris.cockpitng.core.util.bean package instead

pratik_a_soni
Participant

Somehow I feel, this should be OOTB handled. There should be a better way to sort the content. Overwriting editor to just do sort on the labels is too much.

Anyways it works though.

Answers (1)

Answers (1)

jseidl
Explorer

We had a similar case and wanted to disable alphabetic ordering, but rely on the implicit 'sequenceNumber' of the enum values (can be set via backoffice or impex via type EnumerationValue).

We disabled alphabetic auto-sorting and then the sequenceNumber sorting comes into effect:

either per enum:

<editorArea:editor-parameter>
    <editorArea:name>autoSort</editorArea:name>
    <editorArea:value>false</editorArea:value>
</editorArea:editor-parameter>

or globally:

backoffice.cockpitng.defaultenumeditor.autosort=false


see https://help.sap.com/viewer/9b5366ff6eb34df5be29881ff55f97d2/v2105/en-US/8bab4178866910148f93f93b584... for details