Dynamic Listview row numbers?

What's the best way to get dynamic listview rows? I want a rowNum+1 every time a button on the preceding row is clicked.

Update: Found a solution where a button on the preceding row triggers a JS that returns a listview.instances+=1.

If anyone has a more dynamic/flexible solution would appreciate it.

Hi @untethered!

You can use temporary state to manage a variable length for your list view. Open up the Left Sidebar, and under TEMPORARY STATE select "Create a variable to store data." Name it something like "listviewLength", then set it to a default value (e.g., 3).

On data load, you can update the value inside of a javascript query (e.g. listviewLength.setValue(myData.length) ).
Inside your ListView component, you can set the number of rows to be equal to {{ listviewLength.value }}.
Finally, you can add an "Add Row" button and a "Remove Row" button with on-click handlers to modify the listviewLength.
Here is some documentation that goes deeper into working with temporary state: https://docs.retool.com/docs/temporary-state
Let me know if that helps!


Thank you Grace, I wasn't fully aware of this temporary state feature. For now I hardcoded the rows but I'll try to implement this if num of rows users needs is always variable.