How to use a template repeater in a template

I want to use a template repeater within a template, which means a nested template. I set the Repeat Behavior as "Dataset", and binding the Template Parameters to a Dataset. I'm not clear on how to construct a Dataset to make this nested templates work well.

Does anyone have any idea or any example to share ?

I use template and template repeater often. This is first time I try to use a template within a template.

When I create a new vision template, I found it is ok to add a template repeater component in this template, so I think it is feasible to use a template within in a template. but I did not found any examples in Ignition manual or in this forum.

You will certainly have to programmatically construct the dataset for the inner repeater. Search this forum for system.dataset.toDataSet for many, many examples.

I'm quite familiar with this system.dateset.toDataSet functions , I can easy construct a dataset for first template, but how to transfer another dataset can be applied to the second template which is nested in first template? one template instance only receice one dataset.

You cannot nest datasets. You must provide the information in the outer dataset for the template containing the repeater to construct (or indirect bind) the desired inner dataset.

I have finally work out this. with nested dateset. Even it works, I still not feel not very clear about it.

You mean a dataset in an object column of another dataset? I'll be shocked if this doesn't blow up on serialization.


I construct a dynamic dataset called ‘detail’, just as above example, it is a dataset[3R*3C], two columns are with dataset in it. the column 'Detail' is used in first template, and the 'InnerDetail' is used in nested template. Finally, it works well.

Not dataset in object column, just a dataset which with dataset as cells in it. In template repeater property binding, we can only specify one dataset as template parameter. So I use this method to transfer in more than one datasets.

This works in the designer, but does it work if you close the window and re-open it? That's the serialization piece Phil (and I) am worried about. The underlying encoding scheme Vision uses is definitely not designed to support putting datasets inside datasets, so if it does work it's only by "accident" and therefore you're in the realm of "undefined behavior".

Yes, it also works well when I close in designer and open in vision client. I still not quite understand how to provide information in outer dataset to supply the inner nested template. I will further experiment on it. I think if there is an example demo will be better for understanding.

I imagine that this should be done with scripting. The template itself should have a custom property with a name like parameters, and the inner template repeater should be bound to it.

Then, from the outer repeater, or by some other means, the datasets should be dynamically created and assigned to the inner templates' custom properties.

Example:

# Written for the propertyChange event handler of a template repeater
# That repeats a template with nested repeaters
if event.propertyName == 'componentRunning' and event.newValue:
	# ===============
	# Dynamically create headers and data here for the outer repeater
	# ===============
	event.source.templateParams = system.dataset.toDataSet(headers, data)

# Update the inner repeaters here
elif event.propertyName == 'templateParams':
	
	def loadInnerParameters():
		for template in event.source.loadedTemplates:
			# ===============
			# Dynamically create the headers and data for the inner repeaters here, 
			# ...and assign them to the custom properties
			# ===============
			template.parameters = system.dataset.toDataSet(headers, data)
	
	# Wait some arbitrary amount of time [half a second]
	# ...to give the templates time to load
	system.util.invokeLater(loadInnerParameters, 500)