Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The sort feature is not ordering the records properly, when the pojo has a attribute of Calendar type #9

Open
subinks opened this issue Dec 26, 2014 · 1 comment

Comments

@subinks
Copy link

subinks commented Dec 26, 2014

In the Table , the calendar value is showing correctly in dd/MM/yyyy format, but when you click on 'sort ascending' or 'sort descending' , i guess its sorting based on formatted string in dd/MM/yyyy and not based on the actual date value.

The pojo is same as the one given in the test folders

*) public class Person {
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
.
.
@resolvable(formatter = DateFormatter.class)
private GregorianCalendar birth;

//constructor used
public Person(String name, int age, boolean live, String birth) {
this.name = name;
this.age = age;
this.live = live;
this.birth = new GregorianCalendar();
try {
this.birth.setTime(sdf.parse(birth));
} catch (ParseException e) {
e.printStackTrace();
}
}

}

*)DateFormatter.java
public class DateFormatter implements Formatter {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");

@OverRide
public String format(Object arg0) {
return format.format(((GregorianCalendar) arg0).getTime());
}

@OverRide
public String getName() {
return "calendar";
}

@OverRide
public Object parse(Object arg0) {
GregorianCalendar cal = new GregorianCalendar();
try {
cal.setTime(format.parse(arg0.toString()));
} catch (ParseException e) {
e.printStackTrace();
}
return cal;
}

}


*) TableFilterTest.java

here is the code
ObjectTableModel model = new ObjectTableModel(
new AnnotationResolver(Person.class), "name:Name,age:Age,live:Alive,birth:DOB");
model.setEditableDefault(false);
JTable table = new JTable(model);
new TableFilter(table);

model.addAll(PreData.getSampleList());

*)PreData.java
public class PreData {
public static List getSampleList() {
List list2 = new ArrayList();
list2.add(new Person("A", 10,true,"01/04/2014"));
list2.add(new Person("B", 20,true,"01/05/2014"));
list2.add(new Person("C", 30,true,"23/07/2014"));
list2.add(new Person("D", 40,false,"14/02/2014"));
list2.add(new Person("E", 50,false,"10/09/2014"));
return list2;
}

@MarkyVasconcelos
Copy link
Owner

Hmm. yeah.. its String value sort based, I'll try to get a approach to solve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants