[英]Vaadin Grid sortable date column
我想向我的 vaadin 网格组件添加一个可排序的日期列。 不幸的是,它不适用于格式化日期,我认为在格式化日期 object 之后它只是一个字符串,因此使用此列进行排序无法正常工作,但无论如何我需要一个解决方案。 我已经尝试过这个解决方案,它也不起作用:
grid.addColumn(new LocalDateTimeRenderer<>(MyObject::getCreated,
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM)
.withLocale(Locale.GERMANY).withZone(ZoneId.of("Europe/Paris"))))
.setHeader("Created").setSortProperty("created");
你有别的想法吗?
谢谢
您可以设置一个比较器
grid.addColumn(new LocalDateTimeRenderer<>(MyObject::getCreated,
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM)
.withLocale(Locale.GERMANY).withZone(ZoneId.of("Europe/Paris"))))
.setHeader("Created")
.setSortProperty("created")
.setComparator(MyObject::getCreated);
另请查看文档: https://vaadin.com/docs/latest/ds/components/grid#sorting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.