Adjust widget height via javascript in DNG
I have declared the widget height in the xml-file:
<ModulePrefs title="Formal Review" height="300" scrolling='true'>
Now I want to adjust the widget height according to the height of the table via the
javascript file. I can get the table height and the widget height:
let tableHeight = tableElement.offsetHeight
console.log (tableHeight) // answer (e.g.) 412
console.log (window.innerHeight) // answer 300
But all trials to change the widget height does not work. I have tried something like:
window.reSize(200,500)
window.style.height = 500
I am looking forward to any help.
Accepted answer
You need to use gadgets.window.adjustHeight()
Use with no argument to auto size, or use with an argument to set a specific height, eg. gadgets.window.adjustHeight(200);
Comments
thank you for the hint: but if I do so, I get the error message: Cannnot read properties of undefined (reading "adjustHeight").
OK I've just checked my widget.xml file and I have the following declared for the module
<ModulePrefs title="FMEA Assistant" height="680">
<Optional feature="com.ibm.rdm.rm.api"/>
<Require feature="dynamic-height"/>
</ModulePrefs>
<Optional feature="com.ibm.rdm.rm.api"/>
<Require feature="dynamic-height"/>
</ModulePrefs>
See if adding the dynamic-height feature makes the gadget work.
The other issue may be that the code is being called before the objects have been initialised. I have the gadget function calls inside an event listener hooked to 'DOMContentLoaded'
2 votes
Thank you very much. The require feature in the xml-file was missing. Now it works!