Generated cell in table

Hi

I am trying to create a generated column to display the latest one of several dates columns

I have added a column in browse xml

<column id="docsReceiveDate"
                        caption="msg://docsReceiveDate"
                        sortable="true"
                        dateFormat="dd/MM/yyyy"
                        generator="generateDocsReceiveDateCell"/>

and implement this method.

public Component generateDocsReceiveDateCell(PurchaseOrderLine entity) {
        Label label = (Label) componentsFactory.createComponent(Label.NAME);
        label.setValue(getReceiveDate(entity.getPurchaseOrder()));
	return label;
}

the result is as the file attached.

the column generated, but the format is not correct. the column is not sortable.

Is it correct to use label component here?
How should I fix the date format and sortable issue?

Best Regards.
Gabriel

generated_cell

Hi,

  1. column element may contain a nested formatter element that allows you to represent the attribute value in a format different from the standard for this Datatype, e.g.
<column id="date">
    <formatter class="com.haulmont.cuba.gui.components.formatters.DateFormatter" 
               format="dd/MM/yyyy"/>
</column>

So, I suggest using this approach for formatting your date values.
2. Sorting is disabled because table knows nothing about datatype of your column. To enable sorting for this column, I suggest creating a meta property for this value.

@MetaProperty
public Date getDocsReceiveDate() {
	return getReceiveDate(getPurchaseOrder());
}
  1. As I can see from your screenshot, you already have the right date formatting for your application and the only reason you need to add a custom formatting is a generated column. I suppose that adding a temporal type to a meta property will be enough to resolve your needs, e.g.
@Temporal(TemporalType.DATE) 
@MetaProperty
public Date getDocsReceiveDate() {
	return getReceiveDate(getPurchaseOrder());
}

Regards,
Gleb

Hi Gleb,

I am grateful for your reply.

Thank you very much, that is the suggestion what I need.

Best Regards.
Gabriel.

2 posts were split to a new topic: Sorting generated columns