Power Table Component - Client Table Auto Height Scripting

How can I script a Power Table to Size itself based on the number of rows a client is viewing?

Example: I would likethe Power Table (below) to only display the rows that contain data.
Eliminate the grey area at the bottom.

Ignition Support gave me this solution and it solved my dilemma.

In Designer, on the screen that contains the Power Table. Place a Standard Push Button Component.
In the Push Button’s actionPerformed Script Editor write the following script.

print event.source.getComponent('Power Table').getHeight()

Make sure the Output Console is open so you can see the result. Then manually resize your Power table so the header is all that is visible. Toggle to Preview Mode and press this PB. The result in the Output Console will show a value. My test showed a value of 24. Now toggle back to Design Mode and resize the Power Table so the header and one row is visible. Toggle to Preveiw Mode and press your PB. My test showed a value of 52. This is one row height Plus the header height. So, 52 minus 24= 28. Each Row is 28 pixels.
Now right click the Power Table and select scripting then propertyChange and enter the following script.

if event.propertyName == 'viewDataset':
     numRows = event.source.data.getRowCount()
     system.gui.transform(event.source, newHeight=(numRows*28)+24)

Then I added a few lines to keep the Power Table from re-sizing itself too large.
My final script looks like this -

    if event.propertyName == 'viewDataset':
     numRows = event.source.data.getRowCount()
     if numRows <=13:
          system.gui.transform(event.source, newHeight=(numRows*28)+24)
     else: system.gui.transform(event.source, newHeight = 380)

2 Likes