简体   繁体   English

javafx tableview 排序过滤器问题

[英]javafx tableview sort filter issue

I have a javafx table view with several cells.我有一个包含多个单元格的 javafx 表视图。 Sorting is enabled.排序已启用。 Now I have a cell with 2 strings in it, but the sort filters on both of the strings in that cell in asc/desc.现在我有一个包含 2 个字符串的单元格,但是排序过滤器对 asc/desc 中该单元格中的两个字符串进行了过滤。

I would like to make it so that the filter only applies to the first string in the cell, so it ignores string 2.我想让过滤器仅适用于单元格中的第一个字符串,因此它忽略字符串 2。

This is because my sorting gets messaged up because there are two different variables in the cell, of which the second one is not needed for the sort, but the first one is.这是因为我的排序得到了消息,因为单元格中有两个不同的变量,排序不需要第二个变量,但第一个是。 But now the sorting isn't correct because it takes the second string as well.但是现在排序不正确,因为它也需要第二个字符串。

Is this possible?这可能吗? Or do I have to make it two seperate cells?还是我必须使它成为两个单独的单元格?

Just set a comparator on the column.只需在列上设置一个比较器。 Assuming the item type of the column is a string (you can modify it appropriately if this is not the case):假设列的项目类型是字符串(如果不是这种情况,您可以适当修改它):

myColumn.setComparator(Comparator.comparing(s -> {
    int index = s.indexOf(" ");
    if (index == -1) return s ;
    return s.substring(0, index);
}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM