cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Control - Get dimensions of parent

joao_sousa2
Active Contributor
0 Kudos

I'm creating a new control, but in the init/rendeder/onAfterRenderer I would like to know the dimensions (width, height) of the parent control (basically the parent control where I used the "AddContent"). I'm working with D3 and I need to rescale the graphic if the parent is too small.

I've tried several possibilities but no luck, any ideas?

Thank you

Accepted Solutions (1)

Accepted Solutions (1)

PMarti
Active Participant
0 Kudos

Hi Joao, you can get dimensions of parent in your onAfterRendering method as follow:


var oParentControl = this.getParent().$(); // Retrieve jQuery object from parent control.

var width = oParentControl.width();

var height = oParentControl.height();

Regards,

Pau

joao_sousa2
Active Contributor
0 Kudos

Thanks. In my particular case the parent is a sap.ui.layout.Grid

<l:Grid id="teste" defaultSpan="L2 M2 S12"
   width="auto">

The strange thing is that it is returning a 1214 width, when in fact the Grid is much smaller, and the chart is being cut in half. Ever use this on a Grid?

The grid is -xmlview1--teste and the chart is the bottom one, but between them you have that highlighted (dynamic) div that is smaller and I can't seem to access it. That one is defined by the L2 span of the grid.

Edit: Got the div with var elem = this.$().parent() but unfortunately during rendering the width is still full, although when I looked at the finished document (screenshot) the width is 154px.

Answers (0)