sorting on date column in a table, which has String value

Hi,

I’ve BEGIN_DATE and END_DATE as varchar2 datatype in a table. When I use the query to fetch the values for these two columns, I use to_date() to convert them from string to date.

to_date(BEGIN_DATE,‘MM/DD/YYYY’)
to_date(END_DATE,‘MM/DD/YYYY’)

I’m using a ColumnGenerator class to convert the date value into this format (11/30/2011) and display in UI.
public Component generateCell(Table source, Object itemId, Object columnId) {
Property prop = source.getItem(itemId).getItemProperty(columnId);
simpleDateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Date startDate = simpleDateFormat.parse(prop.getValue().toString());
simpleDateFormat = new SimpleDateFormat(“MM/dd/yyyy”);
String dateAsString = simpleDateFormat.format(startDate);
label = new Label(dateAsString);
return label;
}
Now when I do a sort on any of these two columns, it is sorting these values as String instead of Date.

Can you please let me know wht am I missing here?

Thanks

Hi,

the generated columns for the Table are only generated for a subset of all the rows available. Actual sorting will always happen on the container property, which in this case is a String - the generated column is merely masking the original column data in the browser.

To implement the sorting, you have several options. See e.g. the previous discussion
here
. You might create a new container where you actually add the date as a property (instead of the String). Or you might want to override the sort() method of the container.

-tepi

Thank you. Will try that.