0

Is there a way to get the size of an element inside an AbstractCell automatically when the cell is rendered?

The cells I'm rendering, contain a paragraph that can be collapsed by applying

.collapsed {
    overflow: hidden;
    display: block;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-height: 60px;
}

and expanded by removing the collapsed style. Depending on whether the paragraph is collapsed or not, a "read more" / "read less" anchor is added respectively using css.

However, when a paragraph isn't overflown, it's still showing the "read more" anchor that I don't want to display because there isn't anything more to read.

AbstractCell doesn't have an onLoad() or onRander() function, so is there another way to get the paragraph's size after it is loaded?

Any other suggestions about how to tackle this issue are welcome too.

vegasaurus
  • 180
  • 8

1 Answers1

1

After you update your table, you can iterate through all cells and get the width of their content. Just remember to wrap this into a Scheduler. Otherwise you may get all zeros because this code will be executed too fast - before the browser had a chance to render the cells.

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            // update your cells
        }
    });

You can read more about Scheduler here.

Community
  • 1
  • 1
Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • Iterating through the cells, how could I not think of that?! Thanks for pointing me in the right direction, Andrei! – vegasaurus Oct 13 '15 at 14:22