Search in sources :

Example 1 with GridPro

use of com.vaadin.flow.component.gridpro.GridPro in project flow-components by vaadin.

the class MainView method createBeanGridWithEditColumns.

protected void createBeanGridWithEditColumns() {
    GridPro<Person> beanGrid = new GridPro<>(Person.class);
    beanGrid.setColumns();
    beanGrid.setItems(createItems());
    beanGrid.addEditColumn("age").text((item, newValue) -> item.setAge(Integer.valueOf(newValue)));
    TextField textField = new TextField();
    beanGrid.addEditColumn("name").custom(textField, (item, newValue) -> item.setName(newValue));
    List<String> listOptions = new ArrayList<>();
    listOptions.add("Services");
    listOptions.add("Marketing");
    listOptions.add("Sales");
    beanGrid.addEditColumn("department").select((item, newValue) -> {
        item.setDepartment(fromStringRepresentation((newValue)));
    }, listOptions).setHeader("Department").setWidth("300px");
    add(beanGrid);
}
Also used : ArrayList(java.util.ArrayList) TextField(com.vaadin.flow.component.textfield.TextField) GridPro(com.vaadin.flow.component.gridpro.GridPro)

Example 2 with GridPro

use of com.vaadin.flow.component.gridpro.GridPro in project flow-components by vaadin.

the class MainView method createEditorColumns.

protected void createEditorColumns() {
    Div itemDisplayPanel = new Div();
    Div subPropertyDisplayPanel = new Div();
    subPropertyDisplayPanel.setId("prop-panel");
    Div eventsPanel = new Div();
    eventsPanel.setId("events-panel");
    GridPro<Person> grid = new GridPro<>();
    Button disableGrid = new Button("Disable Grid");
    disableGrid.setId("disable-grid-id");
    List<City> cityList = createCityItems();
    List<Person> personList = createItems();
    mapLists(personList, cityList);
    grid.setItems(personList);
    grid.addCellEditStartedListener(e -> eventsPanel.add(e.getItem().toString()));
    grid.addColumn(Person::getAge).setHeader("Age");
    grid.addEditColumn(Person::getName, "name").text((item, newValue) -> {
        item.setName(newValue);
        itemDisplayPanel.setText(item.toString());
        subPropertyDisplayPanel.setText(newValue);
    }).setHeader("Name").setWidth("300px");
    ComboBox<Department> cb = new ComboBox<>();
    cb.setItems(Department.values());
    grid.addEditColumn(Person::getDepartment).custom(cb, (item, newValue) -> {
        item.setDepartment(newValue);
        itemDisplayPanel.setText(item.toString());
        subPropertyDisplayPanel.setText(String.valueOf(newValue));
    }).setHeader("Department").setWidth("300px");
    ComponentRenderer<Span, Person> booleanRenderer = new ComponentRenderer<>(person -> new Span(person.isSubscriber() ? "Yes" : "No"));
    grid.addEditColumn(Person::isSubscriber, booleanRenderer).checkbox((item, newValue) -> {
        item.setSubscriber(newValue);
        itemDisplayPanel.setText(item.toString());
        subPropertyDisplayPanel.setText(newValue.toString());
    }).setHeader("Subscriber").setWidth("300px");
    ComboBox<City> cityCb = new ComboBox<>();
    cityCb.setItems(cityList);
    cityCb.setItemLabelGenerator(City::getName);
    ComponentRenderer<Span, Person> cityRenderer = new ComponentRenderer<>(person -> {
        if (person.getCity() != null) {
            return new Span(person.getCity().getName());
        } else {
            return new Span("");
        }
    });
    grid.addEditColumn(Person::getCity, cityRenderer).custom(cityCb, (item, newValue) -> {
        item.setCity(newValue);
        newValue.setPerson(item);
        itemDisplayPanel.setText(item.toString());
        subPropertyDisplayPanel.setText(newValue.toString());
    }).setHeader("City").setWidth("300px");
    Input customField = new Input();
    grid.addEditColumn(Person::getEmail).custom(customField, (item, newValue) -> item.setEmail(newValue)).setHeader("Email").setWidth("300px");
    disableGrid.addClickListener(click -> grid.setEnabled(false));
    add(grid, itemDisplayPanel, subPropertyDisplayPanel, eventsPanel, disableGrid);
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) Span(com.vaadin.flow.component.html.Span) Div(com.vaadin.flow.component.html.Div) Input(com.vaadin.flow.component.html.Input) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Button(com.vaadin.flow.component.button.Button) GridPro(com.vaadin.flow.component.gridpro.GridPro)

Aggregations

GridPro (com.vaadin.flow.component.gridpro.GridPro)2 Button (com.vaadin.flow.component.button.Button)1 ComboBox (com.vaadin.flow.component.combobox.ComboBox)1 Div (com.vaadin.flow.component.html.Div)1 Input (com.vaadin.flow.component.html.Input)1 Span (com.vaadin.flow.component.html.Span)1 TextField (com.vaadin.flow.component.textfield.TextField)1 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)1 ArrayList (java.util.ArrayList)1