我想向我的 vaadin 網格組件添加一個可排序的日期列。不幸的是,它不適用于格式化日期,我認為在格式化日期物件后它只是一個字串,因此使用此列進行排序無法正常作業,但無論如何我需要一個解決方案。我已經嘗試過這個解決方案,它也不起作用:
grid.addColumn(new LocalDateTimeRenderer<>(MyObject::getCreated,
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM)
.withLocale(Locale.GERMANY).withZone(ZoneId.of("Europe/Paris"))))
.setHeader("Created").setSortProperty("created");
你有別的想法嗎?
謝謝
uj5u.com熱心網友回復:
您可以設定一個比較器
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/410997.html
標籤:
上一篇:每月至每日價值-R
