Andy, I think this is a good solution because it provides everything needed for 
sorting.
Moreover, it complies with the generics of TableColumn.

For example,

var column = new TableColumn<Person, String>("First Name");
SortPolicy<Person, String> sortPolicy = ...
column.setSortPolicy(sortPolicy);

But don't you think the VALUE parameters are redundant since they can be 
obtained directly from ITEM?

Best regards, Pavel

On 5/19/25 22:28, Andy Goryachev wrote:

One possible solution would be to deprecate the comparator property (not for 
removal, keep it for backward compatibility), and add a new property 
'sortPolicy' which will use an interface that can be evolved, as opposed to a 
naive callback.

public interface SortPolicy<ITEM,VALUE> {

public int compare(ITEM itemA, VALUE valueA, ITEM itemB, VALUE valueB);

}

when set, the new property will override the comparator property.

What do you think?

-andy

*From: *openjfx-dev <openjfx-dev-r...@openjdk.org> on behalf of PavelTurk 
<pavelturk2...@gmail.com>
*Date: *Monday, May 19, 2025 at 00:59
*To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org>
*Subject: *Let's discuss JDK-8338952

About six months ago, I opened JDK-8338952 with a proposal to add an item 
comparator to (Tree)TableView.

The reason for this issue is that when using non-standard sorting — for example, when 
there is a "Total"
row in the table — the standard API becomes insufficient. One has to reinvent 
the wheel, and the code
quickly becomes extremely messy. Given that tables are one of the core UI 
components, this becomes
a serious problem.

To address this, I proposed adding an item comparator, which I believe would be 
very simple to implement.
I suggest we at least discuss this issue so we can start moving toward a 
solution.

Best regards, Pavel

Reply via email to