How to add a row in Coda?
distributing a single item or multiple items over rows
Almost every day I am adding rows in the same or in another table. Mostly directed by a button pressed manually. Many makers wrestle with a specific use case like in this question. It is about how to distribute multiple items living in one row over as many rows are there are items.
Multiple items in a cell
I believe that even Coda has adapted my slogan that in Coda everything is a list. As a result when we apply a function, we evaluate or manipulate items in a list. Evaluation means we look at the properties and we apply a rule using a function like count all items, or count only odd items, or filter out people with the first name ‘Christiaan’ and so on. Manipulate means we print the outcome of a (compound) function as item in a cell using a button. The link with the source data is gone because only the outcome is printed as text and not living in a column as a function that recalculates each time the data changes. Buttons are one of the super powers of Coda, but like driving a Ferrari or Lamborghini, it requires a bit of training.
Single Row
In the button you follow the steps and it works. Below an alternative for a button on the canvas following the same procedure.
You click the button and fill out and you see this. The Modal opens in full screen.
and the code behind all this is surprisingly simple:
Simple Distribution
When we have multiple items in a cell we have list of items. Since Coda does not do the counting for us — as she does when items are distributed over rows in a table — we have to set up our own counting and we create a virtual index. This means that we create a number range corresponding with the items, using Sequence()
and each item gets a position via Nth()
. Below how this works.
A variation on this one I gave as feedback in the community. We count the items in the list, we attribute a position via a virtual index and we press the button.
It is a bit more complex when you want to avoid doubles in your target table, but not very much.
Complex Distribution
The two variations above most readers applied already in their docs, at least that is what I assume. The next one is a bit more complicated, but good to follow. It is about only adding rows when the item does not yet exist in the target table. This means that we filter out the already in place items and next only add the new ones.
Our starting point are again multiple employees in one cell like below.
I left a column visible showing the employees to add. It is this function we need in our button. You also notice that I disable the button once there are no employees left to distribute. That is a practical solution and avoids incomprehensible Coda error messages. Below the solution that makes use of a Filter()
and asks for items not present.
In this solution you notice the same pattern. The extra element is the filter we apply on the thisRow and we rename as the outcome. We count the items in the Outcome and we apply the previous logic. This all goes rather fast when you understand that everything is a list in Coda.
Via this doc you can test how it works.
We can always increase complexity, but this blog ends here. In other blogs I will write about complexer functions. I have one in mind about a Sequence()
. Indeed I use the below shown technique to access sub lists.
I hope this article was informative and helpful. Did it help you to solve a problem you unlike would have solved other ways? What about a donation?
My name is Christiaan, and I regularly blog about Coda. While this article is free, my professional services (including consultations) are not, but I’m always happy to chat and explore potential solutions. You can find my free contributions in the Coda Community and on X. The Coda Community is a fantastic resource for free insights, especially when you share a sample doc.