Insert row into data table at set place

What I’m trying to do:
I have repeating panel that is displaying rows from a data table. I added a button to be able to insert a row. I would like this row to be inserted right under the selected row and not at the end.

I saw this code in the forum:

But I don’t understand what its doing or how to modify it to fit my need.

Are there any other examples on how to add rows at a set location?

You can’t rely on the order of the rows in a data table.

You can get the rows in a specific order by sorting them with search(orderby(column)).

The post you are mentioning talks about sql, not data tables using the Anvil APIs.

2 Likes

You shouldn’t rely on the insert order in the data tables for displaying them in that order. Instead you add a field to the table that represents the order (e.g. a date if you want it to be displayed chronologically, a title field for alphabetically, a number field if you want an arbitrary order, etc) and then use tables.order_by on that field when you get search results from that table.

Using tables.order_by you can display data from the same table in different orders, regardless of their insert order. Anvil Docs | Using Data Tables from Python

2 Likes

I am new to Python and databases in general.

I was not aware that row order is not dependable. Thank you both for the clarification. I will add a counter column, or use another method for ordering them.