Table sort by Date column

Hi,

I’m using Vaadin 6.7.4 in my project. So I have a dataset that is retrieved from database and I need populate Table component in the form.

I’m using
formatPropertyvalue
method to format my date column, see below:

add column to the table

mainComponent.addContainerProperty(transactionDt, TDate.class, null);

@Override
protected Table createMainComponentInstance() {
return new Table()
{
/**
*
*/
private static final long serialVersionUID = -8188804282068331981L;

        @Override
        protected String formatPropertyValue(Object rowId, Object colId, Property property) {
            
            // TDate field
            if (property.getType() == TDate.class) {
                SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy");
                try {
                    TDate dt = (TDate) property.getValue();
                    return df.format(dt.getUtilDate());
                }
                catch(Exception ex) {
                    
                }
            }

            return super.formatPropertyValue(rowId, colId, property);
        }            
    };
}

after this format the Header Sort on this column does now work. I’m not able sort at all on this field. So where I’m wrong how to fix?

Hi,

this seems to work fine with a normal java.util.Date property - no difference whether the formatting is there or isn’t. What is this TDate class? Are you sure it implements Comparable? Does the sorting really work if you remove the formatting?

Hi All,

I have another problem. I want to add a CheckBox in a table header. Below are my codes.

Any help is greatly appreciated.

table.addContainerProperty(“Pipeline Type”, CheckBox.class, “”);

    table.addContainerProperty("Mode", String.class, "");
    table.setImmediate(true);

    for (pipelineType : pipelineTypes) {

        // create a new checkbox for the pipeline type
        CheckBox pipelineTypeCheckBox = new CheckBox(
                pipelineType.getShortName());

        Integer itemId = new Integer(pipelineType.getOrderNumber());

        // populating the row
        table.addItem(
                new Object[] { pipelineTypeCheckBox,
                        pipelineType.getDescription() }, itemId);
    }

    table.setPageLength(3);