How to recalculate column widths on scroll down(not programmatic) to a previously hidden row of a Vaadin Grid when its HeightMode is CSS

Deadly 提交于 2019-12-12 23:02:32

问题


My application is similar to Vaadin Dashboard Demo (please click login after you visit this link). So all my mini dashboard items are wrapped around an abstract component that is of height 300px. One of those items is a Grid wrapped around this 300px height abstract component.

My customer hates it when he sees a large column and .v-grid-cell cuts his cell off:

text-overflow: ellipsis;

So in the @PostConstruct of my Vaadin Grid(and everywhere I mess with the container) i have

this.recalculateColumnWidths();

to alleviate my customer's concern. I tell him he can resize the column but he is not satisfied.

When my container size is small, most of the rows are visible and hence the column widths are perfect. When i have a lot of rows i have to scroll. The column widths are calculated based on the set of initially visible rows. When i scroll down, and if a newly visible row has a large column then the column gets cut off.

I can alleviate my problem by using HeightMode.ROW and make the parent Component a scrolling Panel like:

panel.setWidth("100%");
panel.setHeight("310px");

But I have a lot of action going on my Grid's FooterRow and so i don't want my user to have to scroll to the bottom to see the footers if row size is say 100. As a result my Grid has default HeightMode -> HeightMode.CSS. I like it. It always shows my HeaderRow and FooterRow and scrolls only the rows section of my Grid.

What have i tried:

  1. Give each column humongous size or expand ratio. Customer rejected it.

  2. I tried adding a listener for scroll event unsuccessfully. I used this similar question mentions. I could not get the scroll listener turned on.

ScrollingGrid.java:

public class ScrollingGrid extends Grid{


List<ScrollingGridScrollListener> listeners = new ArrayList<ScrollingGridScrollListener>();

private void fireSrollEvent() {
    for (ScrollingGridScrollListener listener : listeners) {
        listener.doGridScroll();
    }
}

public void addScrollListener(ScrollingGridScrollListener listener) {
    listeners.add(listener);
}

@Override
public void beforeClientResponse(boolean initial) {
    super.beforeClientResponse(initial);
    fireSrollEvent();
}

}`

ScrollingGridScrollListener.java:

 public interface ScrollingGridScrollListener {
      public void doGridScroll();
 }

and in my Grid:

  addScrollListener(this);

and

 @Override
public void doGridScroll() {

    Notification.show("You are scrolling!\nYou can add your own behavior here!");
    this.recalculateColumnWidths();
}

I see the notification when page loads. Maybe i should not override beforeClientResponse method in Grid. But I don't know what method to override to achieve a scroll listener.

Help me figure out this scroll listener or if there is another way i can get recalculated column widths on scroll, please let me know.

Thanks for reading this very long question.

Version: 7.6.8

来源:https://stackoverflow.com/questions/39380115/how-to-recalculate-column-widths-on-scroll-downnot-programmatic-to-a-previousl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!