Ask Reuben

resizeFillsEmptySpace

What has happened to the resizeFillsEmptySpace presentation style attribute?

How can I remove the unused white space from a sparse table?

Since the release of Genero 4.00, one of the more common support questions has been about the removal of the resizeFillsEmptySpace presentation style attribute.  This attribute was a presentation style attribute that could be applied to Tables that would automatically stretch the last column so that it took up all the remaining horizontal space of  a table.

When used this presentation style meant that you did not end up with white space to the right of a table.  The two following screenshots using gwc-demo show the difference when resizeFillsEmptySpace is set to no or yes.  In the first image (value=”no”) note the empty white space in the right portion of a table when the columns don’t stretch all the way across the table.  This is magnified when you also use the alternate rows background color as these bars stop rather than continuing all the way across the table.  In the second image (value=”yes”) , note the absence of the empty white space and how the alternate rows background color stretches the full width of the table.

In 4.00 the resizeFillsEmpty space presentation style attribute was removed and has been superseded by use of the STRETCH=X attribute which can be applied to individual columns, or the STRETCHCOLUMNS attribute which can be applied to a TABLE..  See the section on Stretchable columns here.

So rather than having the last column stretch to ensure sure that the table used up all its width, you now have control over what column or columns stretch.  The next two screenshots show demo.per in 4.00, the first with STRETCH=X applied to the “Description” column, the second with STRETCHCOLUMNS applied to the Table.

Note: Also the improvement in 4.00 with the default color for the alternate rows background color.

I am not sad to see resizeFillsEmptySpace go.  As it “Defines if the resize of the table adapts the size of the last column to avoid unused space” applied to the last column, this had flow on effects if the user moved columns around, resized other columns.  The 4.00 solution allows you to select a sensible column or columns to stretch.  The downside is that you have to specify each table individually, unlike the 4st solution which is global.

There is a solution for those that have hundreds and thousands of forms and don’t want to have to edit them to add the applicable STRETCH attribute.  That solution involves the ui.Form.setDefaultInitializer method.  This is a function that you can define to be executed each and every time a form is opened.  You would typically set this as part of a library initialisation routine that is called at the start of every one of your programs.  In the function called, you add logic to add the STRETCHCOLUMNS attribute to the Table node, or to add STRETCH=X to selected columns based on some rule.  You could do the last column as resizeFillsEmptySpace did or you could me more selective.  A possible rule might be any EDIT, LABEL, or BUTTONEDIT column that has a Char datatype i.e not numeric, with width > 15, that is don’t stretch narrow columns or date and numeric columns.

The below is an example of such a function.  The developer would define the rule for a table in the TAG attribute of a TABLE, and if no rule is defined the developer can choose what rule to default to.  In particular to get the equivalent of resizeFillsEmptySpace you would default to “last” by uncommenting the indicated nvl line.  The screenshot shows the result of the different options as indicated by the title of each GROUP box.



-- Called by CALL ui.Form.setDefaultInitializer("my_form_initializer") as part of your initialisation library


FUNCTION my_form_initializer(form_node ui.Form)
    DEFINE table_node, column_node, widget_node om.DomNode
    DEFINE table_list, column_list om.NodeList
    DEFINE table_idx, column_idx INTEGER
    DEFINE mode STRING

    LET table_list = form_node.getNode().selectByPath("/Form//Table")
    FOR table_idx = 1 TO table_list.getLength()
        LET table_node = table_list.item(table_idx)

        LET mode =table_node.getAttribute("tag") # could also use style attribute
        DISPLAY mode
        -- Uncomment this next line to have the equivalent of resizeFillsEmptySpace="yes"
        --LET mode = nvl(mode,"last")
        CASE mode
            WHEN "all" -- Stretch all columns in the table
                IF table_node.getAttribute("stretchColumns") IS NULL THEN
                    CALL table_node.setAttribute("stretchColumns", 1)
                END IF
            WHEN "last" -- Stretch the last column in the table
                LET column_list = table_node.selectByPath("//Table/TableColumn")
                LET column_node = column_list.item(column_list.getLength())
                LET widget_node = column_node.getFirstChild()
                IF widget_node.getAttribute("stretch") IS NULL THEN
                    CALL widget_node.setAttribute("stretch", "x")
                END IF
            WHEN "complex_rule" -- Stretch any Edit that is more than 15 characters wide
                LET column_list = table_node.selectByPath("//Table/TableColumn")
                FOR column_idx = 1 TO column_list.getLength()
                    LET column_node = column_list.item(column_idx)
                    LET widget_node = column_node.getFirstChild()
                    IF widget_node.getAttribute("stretch") IS NULL THEN
                        IF widget_node.getTagName() = "Edit" AND widget_node.getAttribute("width") > 15 THEN
                            CALL widget_node.setAttribute("stretch", "x")
                        END IF
                    END IF
                END FOR
        END CASE
    END FOR
END FUNCTION

One final comment I’ll make is with each new release we do run Early Access Programs (EAP).  For enhancements where it might be one step backward and two steps forward, such as what happened here with resizeFillsEmptySpace, the EAP is the appropriate time to comment.   If you choose not to participate or contribute to EAPs then you do have to face the possibility that there is a change that may negatively impact you.