1818
1919import static java .util .Objects .nonNull ;
2020import static org .dominokit .domino .ui .datatable .plugins .PluginsConstants .DUI_DT_COL_RESIZING ;
21- import static org .dominokit .domino .ui .utils .Domino .*;
2221
2322import elemental2 .dom .HTMLElement ;
2423import java .util .HashMap ;
2524import java .util .Map ;
26- import java .util .Optional ;
2725import java .util .function .Consumer ;
2826import org .dominokit .domino .ui .datatable .ColumnConfig ;
2927import org .dominokit .domino .ui .datatable .DataTable ;
@@ -81,11 +79,7 @@ public void onHeaderAdded(DataTable<T> dataTable, ColumnConfig<T> column) {
8179 EventType .click .getName (),
8280 evt -> {
8381 applySort (
84- column ,
85- sortContext ,
86- Optional .ofNullable (currentSortContext )
87- .map (c -> c .sortDirection )
88- .orElse (SortDirection .DESC ));
82+ column , sortContext , sortContext .sortDirection .next (config .isTriStateSort ()));
8983 });
9084 if (config .isShowSortOptionsInColumnMenu ()) {
9185 column
@@ -121,18 +115,18 @@ private void applySort(
121115 if (config .isShowIconOnSortedColumnOnly () && nonNull (currentSortContext )) {
122116 currentSortContext .sortElement .clearElement ();
123117 }
124- sortContext .sortElement .appendChild (sortContext .sortIcon );
125- updateSort (sortContext );
118+ updateSort (sortContext , sortDirection );
126119 fireSortEvent (sortDirection , column );
120+ currentSortContext .sortElement .appendChild (sortContext .sortIcon );
127121 }
128122 }
129123
130- private void updateSort (SortContext sortContext ) {
124+ private void updateSort (SortContext sortContext , SortDirection sortDirection ) {
131125 if (nonNull (currentSortContext )
132126 && !currentSortContext .columnName .equals (sortContext .columnName )) {
133127 currentSortContext .clear ();
134128 }
135- sortContext .update (true );
129+ sortContext .update (sortDirection );
136130 currentSortContext = sortContext ;
137131 }
138132
@@ -145,7 +139,7 @@ private void updateSort(SortContext sortContext) {
145139 public void sort (SortDirection direction , ColumnConfig <T > column ) {
146140 SortContext sortContext = sortContainers .get (column .getSortKey ());
147141 sortContext .sortDirection = direction ;
148- updateSort (sortContext );
142+ updateSort (sortContext , direction );
149143 fireSortEvent (direction , column );
150144 }
151145
@@ -214,7 +208,7 @@ public SortPlugin<T> configure(Consumer<SortPluginConfig> handler) {
214208 private static class SortContext {
215209 private final String columnName ;
216210 private SortPluginConfig config ;
217- private SortDirection sortDirection = SortDirection .DESC ;
211+ private SortDirection sortDirection = SortDirection .NONE ;
218212 private DominoElement <HTMLElement > sortElement ;
219213 private StateIcon sortIcon ;
220214
@@ -243,7 +237,9 @@ public void clear() {
243237 * Updates the sorting state of the column, optionally flipping the sort direction.
244238 *
245239 * @param flip Whether to flip the sort direction.
240+ * @deprecated use
246241 */
242+ @ Deprecated
247243 public void update (boolean flip ) {
248244 if (flip ) {
249245 if (sortDirection .NONE .equals (sortDirection )) {
@@ -260,5 +256,15 @@ public void update(boolean flip) {
260256 }
261257 sortIcon .setState (sortDirection .name ());
262258 }
259+
260+ /**
261+ * Updates the sorting state of the column, optionally flipping the sort direction.
262+ *
263+ * @param flip Whether to flip the sort direction.
264+ */
265+ void update (SortDirection sortDirection ) {
266+ this .sortDirection = sortDirection ;
267+ sortIcon .setState (sortDirection .name ());
268+ }
263269 }
264270}
0 commit comments