Date pickers and table views in Coda
Show only the selected date range
This blog post was inspired by this post in the Coda community.
Maybe you need to see last week’s sales figures, or perhaps you’re trying to pinpoint what was scheduled for this day last year. This is where the magic of interactive data visualization comes in. By linking a date range selector, like a date picker, to your table, you empower users to effortlessly zoom in on the exact time period they need.
In this post, we’ll explore the challenges of linking date pickers to tables and delve into a practical solution to create a smooth and intuitive user experience.
You may have seen the alternative solution: calculating the difference between today and each date entry in the table. This approach is quite inventive. It’s a handy workaround for smaller datasets, say, a few hundred or even a thousand rows. You can easily calculate “today minus [date]” for each entry and get the results you need.
However, this method has a catch. With larger tables, those calculations can become a performance bottleneck. Imagine dealing with tens of thousands of rows or more — all those calculations can significantly slow down your table and the entire page.
So, while this approach is perfect for simpler situations, more demanding environments require a different strategy. That’s where filtering comes in, and that’s exactly what we’ll explore next.
The filter
Below the screenshot I used in the Coda community.
We’re looking at a classic example of interactive data filtering. Here’s a breakdown of what’s happening in the image:
- Date Picker Control: The user has selected a date range using the date picker tool. This tool allows the user to specify a start and end date to define the desired period.
- Date Range Display: The selected date range is clearly displayed, confirming the user’s input. This provides visual feedback and ensures clarity.
- Filtered Table: The table below is dynamically filtered to show only the entries that fall within the selected date range. This is the core functionality — the date picker acts as a “control” to determine which data is displayed in the table.
The key to this filtering solution lies in understanding how Coda handles date ranges. While it might appear that the date picker simply provides a start and end date, it actually generates a list of those two values. This becomes evident when you examine the underlying formula (by clicking the small “f” icon) which reveals a list with two elements: the first and last dates of the selected range. This list, named after the control itself (in our case, “date range 1”), is then used in our filter to control the table view.
thisRow.[date of contact] >= [date range 1].First() and
thisRow.[date of contact] <= [date range 1].Last()
Interestingly, this approach works even when selecting a single date, as the list simply contains the same date twice. To achieve the filtered view, we use a filter with logical operators. This allows us to create a rule that checks if the “date of contact” in each row falls within the selected range, ensuring both conditions (greater than or equal to the first date and less than or equal to the last date) are met.
Essentially, the solution involves recognizing this hidden list structure and leveraging it within a filter that employs logical operators to accurately display the desired data.
About the filter logic
In Coda, you have two main ways to “filter” what you see:
1. “Filter()” — The Formula Powerhouse: Imagine a sieve that separates specific ingredients from a mixture. That’s what the Filter()
function does in your formulas. It lets you pinpoint exact values (numbers, text, even entire data objects) within a table, like picking out all the red apples from a basket.
2. Filtered View — The Table Transformer: Now imagine putting on a special pair of glasses that only lets you see certain things. That’s a “filtered view” in Coda. It changes how you see the entire table based on rules you set. In our case, we’re using a rule that says, “Only show me rows where the date of contact is within this specific range.”
Both involve filtering, but they operate at different levels: one within a formula (Filter()
), the other on the table display (filtered view). In our date range example, we're using a filtered view to dynamically show only the rows that match the dates we've selected in the control.
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 52 blockbusters!
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.