Skip to content

Commit 12e11f0

Browse files
committed
feat: implement addSortableColumn overload that sets the column key
Close #70
1 parent daacc01 commit 12e11f0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,33 @@ public TwinColGrid<T> addSortableColumn(
328328
return this;
329329
}
330330

331+
/**
332+
* Adds a new sortable text column to this {@link Grid} with a value provider. The column will use
333+
* a {@link TextRenderer}. The value is converted to a String using the provided {@code
334+
* itemLabelGenerator}.
335+
*
336+
* @param itemLabelGenerator the value provider
337+
* @param comparator the in-memory comparator
338+
* @param header the column header
339+
* @param header the column key
340+
* @return this instance
341+
*/
342+
public TwinColGrid<T> addSortableColumn(
343+
final ItemLabelGenerator<T> itemLabelGenerator,
344+
Comparator<T> comparator,
345+
final String header,
346+
final String key) {
347+
forEachSide(
348+
side ->
349+
side.grid
350+
.addColumn(new TextRenderer<>(itemLabelGenerator))
351+
.setHeader(header)
352+
.setComparator(comparator)
353+
.setSortable(true)
354+
.setKey(key));
355+
return this;
356+
}
357+
331358
public TwinColGrid<T> withoutAddAllButton() {
332359
addAllButton.setVisible(false);
333360
checkContainerVisibility();

0 commit comments

Comments
 (0)