Insert new row between two rows

How can I use the API to insert one (or more) rows between two specific existing rows?

It looks like fractions/decimals are allowed in the manualSort column. So is it enough to get the manualSort value of the first row and the second row and then simply make sure the manualSort values of the new “in-between” rows provided in the API call are >first_now.manualSort and <second_row.manualSort?

I tried looking through the grist-core repo to see how you are calculating manualSort values when inserting rows before/after an existing row, but I couldn’t find that specific logic.

Exactly, that’s the correct logic, but there is a simplified method: if you add one or more rows with manualSort set to existingRow.manualSort, the entire batch will get inserted immediately before existingRow. The data engine will adjust manualSort values automatically to be distinct and spread out between the previous row and the following one.

1 Like

Oh, great! That makes it easy. Thanks!