获取未过滤的Java FX TableView列

时间:2017-02-28 09:44:28

标签: java javafx filter tableview

我有一个TableView,其行被过滤,具体取决于您在TextField中键入的内容,使用以下代码搜索所有列:

FilteredList<CommandeFX> filteredData = new FilteredList<>(data, p -> true);

    // 2. Set the filter Predicate whenever the filter changes.
    filterField.textProperty().addListener((observable, oldValue, newValue) -> {
        filteredData.setPredicate(commande -> {
            // If filter text is empty, display all persons.
            if (newValue == null || newValue.isEmpty()) {
                return true;
            }

            // Compare first name and last name of every person with filter text.
            String lowerCaseFilter = newValue.toLowerCase();

            if (String.valueOf(commande.getCodeCommande()).toLowerCase().contains(lowerCaseFilter)) {
                return true;
                 // Filter matches first name.

            } else if (String.valueOf(commande.getCMD()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getClient()).toLowerCase().contains(lowerCaseFilter)) {                                  
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getFournisseur()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getQuantite()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getPrixCommande()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getSommeProperty()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getResteCommandeProperty()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getDateCommande()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getDateReception()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getModified()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }
            else if (String.valueOf(commande.getValide()).toLowerCase().contains(lowerCaseFilter)) {
                return true; // Filter matches last name.
            }

            return false; // Does not match.
        });
    });


    // 3. Wrap the FilteredList in a SortedList. 
    SortedList<CommandeFX> sortedData = new SortedList<>(filteredData);    

    // 4. Bind the SortedList comparator to the TableView comparator.
    sortedData.comparatorProperty().bind(tableCommandes.comparatorProperty());
    // 5. Add sorted (and filtered) data to the table.
    tableCommandes.setItems(sortedData);

到目前为止没问题,我还使用这些代码行来改变某些列的样式(我的情况下的颜色),具体取决于列值(列标题为&#34; reste&#34;):

reste.setCellFactory(column -> {
    return new TableCell<CommandeFX, Number>() {
        @Override
        protected void updateItem(Number item, boolean empty) {
            super.updateItem(item, empty);

            setText(empty ? "" : getItem().toString());
            setGraphic(null);

            TableRow<BonFX> currentRow = getTableRow();

            if (!isEmpty()) {

                if(Float.valueOf((float) item)>0)
                    currentRow.setStyle("-fx-background-color:lightcoral");

            }
        }
    };
});

当我过滤行时,说我有三行都是红色的,过滤后我还有一行显示为红色,很棒!问题是两个不可见的行仍然以红色显示,尽管它们没有显示!如何禁用可见的样式行? 非常感谢你

1 个答案:

答案 0 :(得分:0)

如果您的行为空,请设置其默认颜色:

Full Chip Erase Done.
Programming Done.
Contents mismatch at: 0000001CH  (Flash=00H  Required=C4H) !
Contents mismatch at: 0000001DH  (Flash=00H  Required=DCH) !
Contents mismatch at: 0000001EH  (Flash=00H  Required=FCH) !
Contents mismatch at: 0000001FH  (Flash=00H  Required=DFH) !
Verify Failed!
Error: Flash Download failed  -  "Cortex-M4"