It's all about the answers!

Ask a question

Adjust widget height via javascript in DNG


Antje Rößle-Tuchel (2934) | asked Mar 04, 2:43 a.m.

 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


permanent link
Davyd Norris (2.6k217) | answered Mar 04, 5:21 p.m.
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);
Antje Rößle-Tuchel selected this answer as the correct answer

Comments
Antje Rößle-Tuchel commented Mar 05, 2:25 a.m.

thank you for the hint: but if I do so, I get the error message: Cannnot read properties of undefined (reading "adjustHeight"). 


2
Davyd Norris commented Mar 05, 2:44 a.m. | edited Mar 05, 2:47 a.m.
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>

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'

Antje Rößle-Tuchel commented Mar 05, 8:01 a.m.

 Thank you very much. The require feature in the xml-file was missing. Now it works!

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.