Table with dynamic header and dynamic number of columns | Community
Skip to main content
davids88333804
Level 2
March 9, 2024

Table with dynamic header and dynamic number of columns

  • March 9, 2024
  • 2 replies
  • 3377 views

Hello!

 

I would like to design a static form with a dynamic table.

The table gets the number of columns, the length of each column and the header text from the backend. On every page the table header should appear (as an overflow header).

 

What would be the best approach?

 

The things I tried:

  • Create a table from scratch with subforms -> overflow header is not working, cannot set width on a new page, the header cells (in a flowed subform) just stay on top of each other.
  • Create a normal table (from Object Library) -> cannot hide the columns that I do not need.
  • Create 10 normal tables (from Object Library), because I can have only 1 - 10 columns, hiding the unwanted table by script depending on the input data  -> data cannot flow twice to tables even if all other tables are inactive.

 

Thanks for any help, best regards, David.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

radzmar
Level 10
March 12, 2024

A static form can't have any dynamic elements. To do so you need a dynamic form. There you can add, remove, show or hide columns by placing subforms in the table cells. Those subforms can be controlled as usual. 

davids88333804
Level 2
March 12, 2024

Hi Radzmar!

 

Sorry, I dunno why I wrote Static form I am always creating dynamic forms.

My problem is still the same. I get the number of columns and the header texts from the backend (SAP). ...and I have a requirement to print the header on each page in case the table overflows. Either I use the normal table object or I make it from scratch with subforms, something is always missing.

My last solution was to create as many tables as columns we can have (10 in my case) and hide them except the one we need. The width of the columns can be set and the text as well, and the overflow header is at its place, but it is still a lame solution. Not to talk about the other great feature - I have to pass the same data 10 times in the interface to populate the tables (…why is it good for anyone that the table data gets “consumed”???). I just wondered if anyone has a better solution.

Thanks, and best regards, David.

davids88333804
Level 2
March 17, 2024

Creating a dynamic table with multiple columns is not so complicated. You only need to wrap the the fields in all rows the are in the same column with a subform that ist set to be repeatable, like in this example. 

 

Then you need a script that controls the table. Here it's placed in the exit event of the numeric field named "Field".

if (!this.isNull) { var nColumns = this.rawValue, // Number of columns oRows = Table1.resolveNodes('#subform[*]'), // Resolve all rows of the table nMaxWidth = 150, // maximum width for all repeatable columns cColumsWidths = "30mm "; // initial value for table properties // Process each row for (var i = 0; i < oRows.length; i += 1) { oRows.item(i).Column.instanceManager.setInstances(nColumns); // Set selected number of columns per row var oRowColumns = oRows.item(i).resolveNodes('Column[*]'); // Resolve all columns per row // Process each column per row for (var c = 0; c < nColumns; c += 1) { // Add width of repeatable colums to table properties. Do this only for the first row, since it's needed only once if (i === 0) { cColumsWidths += (nMaxWidth / nColumns) + "mm "; } // Set width of nested text field in every repeated column oRowColumns.item(c).resolveNode('#field').w = (nMaxWidth / nColumns) + "mm"; } } // Update columns width in table properties Table1.columnWidths = cColumsWidths; }

 

The table layout changes as soon you left the field.

 


Hi Radzmar!

Thx, for the suggestion, but I have similar code myself. The problem still persists - no header in case the table overflows! Either I use fix header (that is not possible in my case - since I get the number of columns, the length of the columns and rawvalue of the header cells) or I use a dynamic header, then the overflow header gets all messed up....do you have any suggestion on that one? Thx, best regards, David.

kautuk_sahni
Community Manager
Community Manager
March 20, 2024

@davids88333804 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni