You are viewing limited content. For full access, please sign in.

Question

Question

Set number of rows in a table from a lookup

asked on January 4, 2017

I am looking for a way to dynamically set the number of rows to display in a table based on a lookup.  My lookup will return a count of the rows needed to populate in a hidden field (q142).  Then the data will return an populate each row of the table with the corresponding data.  I've included an image below to help further explain:

As mentioned, the lookup will return a numeric value that will represent the number of rows that should be display in the above table.  Any help is much appreciated.  

0 0

Answer

SELECTED ANSWER
replied on January 5, 2017

You can try script like this:

$(document).ready(function(){
    $("#Field5").change(addrows);
	function addrows() {
      	$(".cf-table-delete").click();
    	var rownumber = $("#Field5").val();
    	for (i=0; i < rownumber; i++){
      		$('#q3').trigger('click');
    	}
    }
});

#q3 is the id for "Add" button, while #Field5 is the id for the number field.

0 0

Replies

replied on January 4, 2017

Hi Nate,

If you are using lookup to fill the table with data, then I would suggest using "fill as new rows" option on lookup, like this:

With this option, the number of rows is set dynamically based on lookup return data.

But if you are not filling table by lookup, or need empty rows, you can do it by using custom JavaScript. In this case, the "Add" button in the table should be visible and you can use JavaScript to click the "Add" button to add new rows.

0 0
replied on January 5, 2017

Rui,

Thanks for the quick reply.  I am not using v10, yet.  I tried to upgrade yesterday and had some issues so I reverted back to 9.2.  Do you know an easy way to do this with Javascript?  

Thanks,

Nate

0 0
SELECTED ANSWER
replied on January 5, 2017

You can try script like this:

$(document).ready(function(){
    $("#Field5").change(addrows);
	function addrows() {
      	$(".cf-table-delete").click();
    	var rownumber = $("#Field5").val();
    	for (i=0; i < rownumber; i++){
      		$('#q3').trigger('click');
    	}
    }
});

#q3 is the id for "Add" button, while #Field5 is the id for the number field.

0 0
replied on January 6, 2017

This worked perfect.  Thanks Rui.  

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.