I’m having this same sorting issue. I must be missing something because I’m not sure where or how I have to define the MetaProperty to get this to work.
My generated cell is formatted correctly and displaying the correct data, but I’m not sure how to tell the system to sort it. So far all my attempts at defining the probably missing datatype have failed. I don’t get any errors, but the column I’ve generated does not respond to clicks.
public Component generateExpiryDateCell(CustomerOffer entity) {
Label label = (Label) componentsFactory.createComponent(Label.NAME);
label.setValue(getExpiryDate(entity));
return label;
}
@Temporal(TemporalType.DATE)
@MetaProperty
public Date getExpiryDate(CustomerOffer entity) {
return Date.from((LocalDateTime.ofInstant(entity.getCreateTs().toInstant(), ZoneId.systemDefault()).plusDays(entity.getOffer().getExpire_after())).atZone(ZoneId.systemDefault()).toInstant());
}
In this particular case, you don’t need to use generated columns, a simple @MetaProperty that calculates dates will be enough. Also, a meta property can’t be used as a util method as in the example above, i.e. it can’t have input parameters.
Let’s assume that I have an entity CustomerOffer:
@NamePattern("%s|name")
@Table(name = "DEMO_CUSTOMER_OFFER")
@Entity(name = "demo$CustomerOffer")
public class CustomerOffer extends StandardEntity {
private static final long serialVersionUID = -6101720560346863464L;
@NotNull
@Column(name = "NAME", nullable = false)
protected String name;
@NotNull
@Lob
@Column(name = "DESCRIPTION", nullable = false)
protected String description;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
@Temporal(TemporalType.DATE)
@MetaProperty(related = "createTs")
public Date getExpiryDate() {
return DateUtils.addDays(getCreateTs(), 10);
}
}
Pay attention to the getExpiryDate which is a read-only meta property implemented with a method:
@Temporal(TemporalType.DATE)
@MetaProperty(related = "createTs")
public Date getExpiryDate() {
return DateUtils.addDays(getCreateTs(), 10);
}
Now, I can add this property to a view:
And use it in screens, for instance in the browser screen: