Modify rows in Coda

Modify rows using a canvas button

Why you need the Foreach() function in Coda

Christiaan Huizer

--

It is all about this formula I created to showcase a client how to manipulate a table via a canvas button. The objective was to check some boxes based on a criteria. In our example that is a task and we we want to check all the boxes for this task.

action formula written on the canvas

You might be surprised to see an action formula written directly on the canvas. Typically, action formulas belong in buttons or automations, not displayed like this. However, I’m showing it to you here for demonstration purposes. This specific formula doesn’t actually do anything in this context; it simply illustrates how an action can be triggered a certain number of times when used in a button or automation.

You notice a few key parts:

  1. Table and Filter: It starts by targeting a table and filtering it by the “Task” column. We’re looking for all tasks where the task number is “task 1”. This creates a list of rows that match this condition.
  2. Iteration: We then use a foreach() function to iterate over this list. For each item in the list (represented by “currentvalue”), the formula modifies something.
  3. Modification: Inside the loop, the formula targets the “checkbox” column within each row and sets its value to “true” — essentially checking the box.

That’s it! This formula simply checks the “checkbox” column for every task labeled as task number one. Let’s take a closer look at how this works.

Some basics

We first look at the references we see below in blue. It is a list as the outcome of a filter with so called objects living in the display column. Maybe you already made use of it by opening the code editor and typing @ to access a specific objectsin your doc like a user.

producing the objects as items in a list

Within the ForEach() function, each item from the list is renamed as CurrentValue. This might seem a bit perplexing initially, but once you grasp that ForEach() meticulously processes each item and executes a specific action on it, the purpose becomes clear. It's a concise way of expressing exactly that functionality.

In this example, the Foreach() function modifies rows within the same table that was initially filtered. The filter generates a list of objects (items), which are then used as a starting point. Each item is associated with a specific column and we define the value to be placed in the corresponding cell of that row. While the term "print" is sometimes used technically, it can be misleading for non-native English speakers, who might associate it with a physical document from a printer. In this context, it's clearer to say that we are assigning or setting a value in each cell.

It works

Previously I wrote this blog about modifyRows()

Hopefully, this post has shed some light on this common Coda challenge and empowered you to create more interactive and insightful data experiences. On a personal note, creating these in-depth posts takes a lot of time and effort. While I love sharing my knowledge, a little support goes a long way. If you found this helpful, what about a donation or sharing this post with your fellow Coda enthusiasts? Every bit of encouragement helps fuel the next blogs!

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.

--

--

Christiaan Huizer
Christiaan Huizer

Written by Christiaan Huizer

I write about how to Coda . You find blogs for beginners and experienced makers. I publish about 1 / week. Welcome!

No responses yet