I have some questions on sorting best practices with enums and custom sorting with and without paging in a list grid. We are using Smart Client v8.3p_2013-07-18/Pro Deployment and have a data source that has a field 'aStatusField' of type enum. When I sort this column in the ListGrid, it sorts them alphabetically - "In Progress," "Resolved," and "Unresolved." However, I want to have them logically sorted as "Unresolved," "In Progress," and "Resolved." The data source and the java enum for representing the Status is copied below.
I have been reading up a lot on sorting and I understand that sorting has to be done differently on the server-side and client-side.
If sorting is done on the client-side, I can have a sortNormalizer function on the status field in the ListGrid and could have a map representing the text value and the order similar to the java enum.
However, it would be ideal if I could use the enum itself for this. Is there a way to do this? Below is the snippet for the data source generated.
Thanks for your help in advance.
Code:
<DataSource ID="MyPageDS" serverConstructor="spring:myPageDataSource" schemaBean="com.mycompany.MyPage" validateRelatedRecords="true"> <fields> <field primaryKey="true" name="id" title="ID" type="sequence" /> … <field name="aStatusField" type="enum" valueMapEnum="com.mycompany.StatusEnum" /> </fields> </DataSource>
Code:
public enum StatusEnum {
Unresolved("Unresolved"),
InProgress("In Progress"),
Resolved("Resolved");
private String value;
private int order;
private StatusEnum(final String value) {
this.value = value;
}
}
If sorting is done on the client-side, I can have a sortNormalizer function on the status field in the ListGrid and could have a map representing the text value and the order similar to the java enum.
Code:
var statusSortMap = {
"Unresolved": 1,
"In Progress": 2,
"Resolved": 3
};
…
sortNormalizer: function(record, fieldName) {
var status = record.aStatusField;
return statusSortMap[status];
}
Code:
isc.DataSource.create({
ID:"MyPageDS",
...
fields: [
...
{
valueMap:{
Resolved:"Resolved",
Unresolved:"Unresolved",
InProgress:"In Progress"
},
valueMapEnum:"com.mycompany.StatusEnum",
name:"aStatusField",
type:"enum"
}
]
})
Comment