Coder Social home page Coder Social logo

Comments (4)

tomivirkki avatar tomivirkki commented on September 25, 2024

Tried with the following on Vaadin 14.4.8:

List<Person> items = new ArrayList<>();

// 1. instantiate grid and columns
Grid<Person> grid;
grid = new Grid<>();
grid.addColumn(item -> items.indexOf(item) + 1).setHeader("#");
grid.addColumn(Person::getEmail).setHeader("A").setKey("TEST");
grid.addColumn(Person::getFirstName).setHeader("B");
grid.addColumn(Person::getLastName).setHeader("C");

items.add(new Person(100, "Lucas", "Kane", 68, new Address("12080", "Washington"), "127-942-237"));
grid.setItems(items);

// 2. hide column
grid.getColumnByKey("TEST").setVisible(false);

// 3. add item to list
items.add(new Person(101, "Foo", "Bar", 53, new Address("12080", "Washington"), "127-942-237"));

// 4. refresh data provider
grid.getDataProvider().refreshAll();

add(grid);

Works as expected:
Screenshot 2021-02-26 at 9 17 00

Please provide an example project that the issue can be reproduced with.

from vaadin-grid.

drewharvey avatar drewharvey commented on September 25, 2024

Maybe the issue is when each step is broken down into actions from the user. In a fresh project, the following is giving me the exception. When you run the project, as a user on the UI, click the buttons from top to bottom. After the last button you will see the exception.

grid-issue-gif

package org.vaadin.spring.tutorial;

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;

import java.util.ArrayList;
import java.util.List;

@Route
public class MainView extends VerticalLayout { // implements LocaleChangeObserver {

    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Grid<Person> grid;
    private List<Person> items = new ArrayList<>();

    public MainView() {
        btn1 = new Button("1. Add record", event -> {
            addRecord();
            btn1.setEnabled(false);
            btn2.setEnabled(true);
            btn3.setEnabled(false);
        });

        btn2 = new Button("2. Hide column 'A'", event -> {
            grid.getColumnByKey("TEST").setVisible(false);
            btn1.setEnabled(false);
            btn2.setEnabled(false);
            btn3.setEnabled(true);
        });
        btn2.setEnabled(false);

        btn3 = new Button("3. Add record", event -> addRecord());
        btn3.setEnabled(false);
        
        grid = new Grid<>();
        grid.addColumn(item -> items.indexOf(item)+1).setHeader("#");
        grid.addColumn(Person::getFirstName).setHeader("A").setKey("TEST");
        grid.addColumn(Person::getLastName).setHeader("B");
        grid.addColumn(Person::getHaircut).setHeader("C");
        grid.setItems(items);

        add(btn1, btn2, btn3, grid);
    }

    private void addRecord() {
        items.add(new Person("ted", "johnson", "bowlcut"));
        grid.getDataProvider().refreshAll();
    }

    public class Person {
        private String firstName;
        private String lastName;
        private String haircut;

        public Person(String firstName, String lastName, String haircut) {
            this.firstName = firstName;
            this.lastName = lastName;
            this.haircut = haircut;
        }

        public String getFirstName() {
            return firstName;
        }

        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }

        public String getLastName() {
            return lastName;
        }

        public void setLastName(String lastName) {
            this.lastName = lastName;
        }

        public String getHaircut() {
            return haircut;
        }

        public void setHaircut(String haircut) {
            this.haircut = haircut;
        }
    }

}

from vaadin-grid.

arenk avatar arenk commented on September 25, 2024

@sosa-vaadin I have a similar issue with _setFooterTemplateOrRenderer.

More precisely: I'm getting a client-side exception when doing the following sequence: instantiate grid with a footer row, hide a column, update some grid properties (incl. text in the footer row of active columns), and then call refreshAll on the data provider.

An easy fix probably would be to add the same additional check as in #2144 && !this.hidden to _setFooterTemplateOrRenderer in vaadin-grid-column.js

from vaadin-grid.

sosa-vaadin avatar sosa-vaadin commented on September 25, 2024

@arenk Please open a ticket in https://www.github.com/vaadin/web-components so it will get done. After that, you can open a PR yourself and we'll take a look at it.

from vaadin-grid.

Related Issues (20)

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.