| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |||
| 8 | 8 | ||
| 9 | 9 | ### Added | |
| 10 | 10 | ||
| 11 | - - Add [`Ordered`](https://patternfly-java.github.io/patternfly-java/org/patternfly/component/Ordered.html) interface and implementations for `List`, and `DataList`. | ||
| 11 | + - Add [`Ordered`](https://patternfly-java.github.io/patternfly-java/org/patternfly/component/Ordered.html) interface and implementations for `List`, `DataList`, and `Tbody`. | ||
| 12 | 12 | ||
| 13 | 13 | ## [0.4.16] - 2026-02-05 | |
| 14 | 14 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | package org.patternfly.component.table; | |
| 17 | 17 | ||
| 18 | 18 | import java.util.ArrayList; | |
| 19 | + import java.util.Comparator; | ||
| 19 | 20 | import java.util.Iterator; | |
| 20 | 21 | import java.util.LinkedHashMap; | |
| 21 | 22 | import java.util.List; | |
@@ -26,8 +27,8 @@ | |||
| 26 | 27 | import org.jboss.elemento.Elements; | |
| 27 | 28 | import org.jboss.elemento.Id; | |
| 28 | 29 | import org.patternfly.component.HasItems; | |
| 30 | + import org.patternfly.component.Ordered; | ||
| 29 | 31 | import org.patternfly.component.emptystate.EmptyState; | |
| 30 | - | ||
| 31 | 32 | import elemental2.dom.HTMLTableSectionElement; | |
| 32 | 33 | ||
| 33 | 34 | import static org.jboss.elemento.Elements.failSafeRemoveFromParent; | |
@@ -42,6 +43,7 @@ | |||
| 42 | 43 | import static org.patternfly.style.Classes.tbody; | |
| 43 | 44 | ||
| 44 | 45 | public class Tbody extends TableSubComponent<HTMLTableSectionElement, Tbody> implements | |
| 46 | + Ordered<HTMLTableSectionElement, Tbody, Tr>, | ||
| 45 | 47 | HasItems<HTMLTableSectionElement, Tbody, Tr> { | |
| 46 | 48 | ||
| 47 | 49 | // ------------------------------------------------------ factory | |
@@ -57,9 +59,10 @@ public static Tbody tbody() { | |||
| 57 | 59 | ||
| 58 | 60 | public static final String SUB_COMPONENT_NAME = "tbd"; | |
| 59 | 61 | final Map<String, Tr> items; | |
| 60 | - private Tr emptyRow; | ||
| 61 | 62 | private final List<BiConsumer<Tbody, Tr>> onAdd; | |
| 62 | 63 | private final List<BiConsumer<Tbody, Tr>> onRemove; | |
| 64 | + private Tr emptyRow; | ||
| 65 | + private Comparator<Tr> comparator; | ||
| 63 | 66 | ||
| 64 | 67 | Tbody() { | |
| 65 | 68 | super(SUB_COMPONENT_NAME, Elements.tbody().css(component(table, tbody)) | |
@@ -83,15 +86,25 @@ public Tbody addRow(Tr row) { | |||
| 83 | 86 | } | |
| 84 | 87 | ||
| 85 | 88 | public Tbody add(Tr row) { | |
| 86 | - items.put(row.identifier(), row); | ||
| 89 | + if (comparator != null) { | ||
| 90 | + addOrdered(this, this, row, comparator); | ||
| 91 | + } else { | ||
| 92 | + add(row.element()); | ||
| 93 | + } | ||
| 87 | 94 | row.tbody = this; | |
| 88 | - add(row.element()); | ||
| 95 | + items.put(row.identifier(), row); | ||
| 89 | 96 | onAdd.forEach(bc -> bc.accept(this, row)); | |
| 90 | 97 | return this; | |
| 91 | 98 | } | |
| 92 | 99 | ||
| 93 | 100 | // ------------------------------------------------------ builder | |
| 94 | 101 | ||
| 102 | + @Override | ||
| 103 | + public Tbody ordered(Comparator<Tr> comparator) { | ||
| 104 | + this.comparator = comparator; | ||
| 105 | + return this; | ||
| 106 | + } | ||
| 107 | + | ||
| 95 | 108 | @Override | |
| 96 | 109 | public Tbody that() { | |
| 97 | 110 | return this; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments