Giter VIP home page Giter VIP logo

jfxtableview's Introduction

Maven Central

JFXTableView

Advanced JavaFx TableView with filtering and total functions.

Description

The implementation of the filter is easy. You wrap your TableView with the JFXTableView and add the columns which wrap JFXTableColumn.

There are the following column implementations:

  • JFXBooleanTableColumn
  • JFXDoubleTableColumn
  • JFXFloatTableColumn
  • JFXIntegerTableColumn
  • JFXLocalDateTableColumn
  • JFXLocalDateTimeTableColumn
  • JFXLocalTimeTableColumn
  • JFXLongTableColumn
  • JFXStringTableColumn
  • JFXBigDecimalTableColumn

You can create your own column implementation by inheriting from the abstract JFXTableColumn class.

You can turn off filtering on a table by passing false to the setAllowFiltering method. Example:

jfxTableView.setAllowFiltering(false);

The following types of filtering are supported (The filter types available depend on the choice of the JFXTableColumn implementation):

  • Equals
  • Not equals
  • Greather or equals than
  • Greather than
  • Less or equals than
  • Less than
  • Start with
  • End with
  • Contains
  • Not contains
  • Regular expression
  • Custom filtering

The following types of column totals are supported (The totals types available depend on the choice of the JFXTableColumn implementation):

  • Sum
  • Minimum
  • Maximum
  • Average

Features

JFXTableView supports the following features:

  • Filtering rows by columns (multiple filter option with Custom filtering by column)
  • Totals by column
  • Count rows
  • Copy cell value from context menu
  • Export to file
  • Localization and internationalization

Get Started

Create table JFXTableView and columns JFXTableColumn:

//custom model for JFXTableView
class Model {
    private SimpleBooleanProperty boolValue = new SimpleBooleanProperty();
    private SimpleDoubleProperty doubleValue = new SimpleDoubleProperty();
    private SimpleFloatProperty floatValue= new SimpleFloatProperty();
    private SimpleIntegerProperty integerValue = new SimpleIntegerProperty();
    private SimpleLongProperty longValue = new SimpleLongProperty();
    private SimpleStringProperty stringValue = new SimpleStringProperty();
    private SimpleObjectProperty<LocalDate> localDateValue = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDateTime> localDateTimeValue = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalTime> localTimeValue = new SimpleObjectProperty<>();
    
    //getters and setters
}

//initialize JFXTableView
//background is StackPane (usually this is Node on which the controls are located in the scene), which is necessary for the darkening effect when opening dialog boxes
JFXTableView<Model> jfxTableView = new JFXTableView<>(background);

//initialize JFXTableColumns
JFXTableColumn<Model, Boolean> boolColumn = new JFXBooleanTableColumn<>("Bool value");
boolColumn.setCellValueFactory(new PropertyValueFactory<>("boolValue"));

JFXTableColumn<Model, Double> doubleColumn = new JFXDoubleTableColumn<>("Double value");
doubleColumn.setCellValueFactory(new PropertyValueFactory<>("doubleValue"));

JFXTableColumn<Model, Float> floatColumn = new JFXFloatTableColumn<>("Float value");
floatColumn.setCellValueFactory(new PropertyValueFactory<>("floatValue"));

JFXTableColumn<Model, Integer> integerColumn = new JFXIntegerTableColumn<>("Integer value");
integerColumn.setCellValueFactory(new PropertyValueFactory<>("integerValue"));

JFXTableColumn<Model, Long> longColumn = new JFXLongTableColumn<>("Long value");
longColumn.setCellValueFactory(new PropertyValueFactory<>("longValue"));

JFXTableColumn<Model, LocalDate> localDateColumn = new JFXLocalDateTableColumn<>("LocalDate value");
localDateColumn.setCellValueFactory(new PropertyValueFactory<>("localDateValue"));

JFXTableColumn<Model, LocalDateTime> localDateTimeColumn = new JFXLocalDateTimeTableColumn<>("LocalDateTime value");
localDateTimeColumn.setCellValueFactory(new PropertyValueFactory<>("localDateTimeValue"));

JFXTableColumn<Model, LocalTime> localTimeColumn = new JFXLocalTimeTableColumn<>("LocalTime value");
localTimeColumn.setCellValueFactory(new PropertyValueFactory<>("localTimeValue"));

JFXTableColumn<Model, String> stringColumn = new JFXStringTableColumn<>("String value");
stringColumn.setCellValueFactory(new PropertyValueFactory<>("stringValue"));

//add columns to JFXTableView
jfxTableView.getColumns().addAll(boolColumn, doubleColumn, floatColumn, integerColumn, longColumn,
        localDateColumn, localDateTimeColumn, localTimeColumn, stringColumn);

//initialize data
ObservableList<Model> data = FXCollections.observableArrayList();
Model row1 = new Model();
row1.setBoolValue(true);
row1.setDoubleValue(1);
row1.setFloatValue(2);
row1.setIntegerValue(3);
row1.setLocalDateTimeValue(LocalDateTime.now());
row1.setLocalDateValue(LocalDate.now());
row1.setLocalTimeValue(LocalTime.now());
row1.setLongValue(4);
row1.setStringValue("string");
data.add(row1);

//set data to JFXTableView
jfxTableView.setData(data);

Result: Result

background is StackPane (usually this is Node on which the controls are located in the scene), which is necessary for the darkening effect when opening dialog boxes. For example with shadow:

With Shadow

Without shadow:

Without Shadow

Numbered rows

First column used for display numbered rows. Unvisible by default, use setVisibleNumberedRowsColumn method for table.

//set visible numbered rows column for JFXTableView
jfxTableView.setVisibleNumberedRowsColumn();

Export to file

First (or second if numbered rows visible) column have burger menu button. Use popup action for export data to file.

By default export data to CSV file, but you can write your own implementation and pass a reference to the method in jfxTableView.setExportDataAction (To get data from the table use the jfxTableView.getDataForExport() method).

Localization and internationalization

For localization and internationalization use Resource bundle message. Available by default en and ru_RU.

Credits

jfxtableview's People

Contributors

evgen2sat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

boohsia fxq0109

jfxtableview's Issues

Implementation of checkbox rendering in cells for boolean type

I have implemented checkbox rendering in cells for boolean in case you want to use

public class CheckBoxTableCellFactory<S, T>
    implements Callback<JFXTableColumn<S, T>, TableCell<S, T>> {

  @Override
  public TableCell<S, T> call(JFXTableColumn<S, T> param) {
    final CheckBox checkBox = new CheckBox();
    checkBox.setDisable(true);
    final TableCell<S, T> cell =
        new TableCell<S, T>() {
          @Override
          public void updateItem(T item, boolean empty) {
            super.updateItem(item, empty);
            if (isEmpty()) {
              setGraphic(null);
            } else {
              setGraphic(checkBox);
              checkBox.setSelected((boolean) item);
            }
          }
        };
    cell.setGraphic(checkBox);
    cell.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    cell.setAlignment(Pos.CENTER);
    return cell;
  }
}

And in JFXTableColumn

private void initCell() {
    if (this instanceof JFXBooleanTableColumn) {
      setCellFactory(param -> new CheckBoxTableCellFactory<S, T>().call(this));
    } else {
      setCellFactory(param -> new DefaultTableCell<S, T>().call(this));
    }
  }

p.s i would have done that with pull request but i have trouble with gradle and i am more a maven guy :D

Saving and reloading filters

I was wondering how one might be able to "save" filter settings to be reloaded in the future (assuming the same table data model etc). For example, on filtering String values, having several String "equals" conditions to be later retrieved quickly without having to re-input them each time? If not currently possible, what do you think would be the best way to do this? Thanks and cheers

Option to hide first column

I haven't find anything like this maybe i miss something . It might be useful to be able to hide it in case you don't want numbered lines

Adding CheckComboBox (ControlsFX) as a column filter type

Greetings,
This is a fantastic addition to the javafx community. I really love using this. I was wondering how feasible it would be to add an additional column filtering type (on Strings) using a CheckComboBox (org.controlsfx) to select a variety of String values typically used as categories.
Thanks for considering. Cheers

Equal BigDecimals is wrong

Equal bigdecimal is wrong according to article

https://blogs.oracle.com/javamagazine/four-common-pitfalls-of-the-bigdecimal-class-and-how-to-avoid-them

BigDecimal x = new BigDecimal("1");
BigDecimal y = new BigDecimal("1.0");
System.out.println(x.equals(y));

The console output is the following:

False

This output is due to the fact that a BigDecimal consists of an unscaled integer value with arbitrary precision and a 32-bit integer scale, both of which must be equal to the corresponding values of the other BigDecimal that’s being compared. In this case

x has an unscaled value of 1 and a scale of 0.
y has an unscaled value of 10 and a scale of 1.

Hence, x is not equal to y.

So x.compareTo(y) == 0 instead of equal should be more proper

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.