Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Using a Drop-down list to dynamically determine how many rows are in a table

Avatar

Level 2

I would like to have a drop-down list that is pre-populated with number determine the number if rows that are in a table.  Does anybody have an example they could show me?

Thanks,

Paul

6 Replies

Avatar

Level 9

Hello Paul,

What's the structure of the table? Is a static one or you are adding rows dynamically?

Lets say it is a static one and the Row numbers are Row1, Row2, Row3 etc. You can write a script to count the number of the rows and in the initialize event of the DropDown you can put the value.

var thisElement ;

    var nodeLength = Table1.nodes.length; // Counts the total nodes present in the table.

    var rowCount = 0;

    for (var i=0; i<nodeLength; i++) { // Loops through the number of rows

        thisElement = Table1.nodes.item(i) ;

   if (thisElement.className == "subform") { // As every row is a subform it searches the term row, if found it increments the row count.

     if(thisElement.name.indexOf("Row") != -1 ){

      rowCount ++;

    }

         

        }

    }

In the DropDown initialize event = this.rawValue = rowCount;

If the table is dynamic and lets say you are adding the instance of Row1.

then var rowCount = Table1.Row1.instanceManager.count;

Here in the click event of adding button you can put the above script.

Thanks,

Bibhu.

Avatar

Level 2

What I actually want to do is have the number of rows change depending on the number selected from the dropdown list.

Avatar

Level 9

Then in that case you can use the setInsance method to set the no.of rows.

Avatar

Level 2

Can you elaborate on this. What would be the syntax of this command.

Avatar

Level 9

var a; // set the variable depending upoen your need.

form1.Table1.Row1.instanceManager.setInstances(a);

Thanks,

Bibhu.

Avatar

Level 2

If I use the value zero it does not work.  How would I remove all the row instances if the value is zero.