Data Studio Field Filters

I am exploring the capabilities of Directus. Could it be a swiss army knife? A headless cms, automation tool and a internal app in one? I also use Strapi, but I want to use Directus for real low-code solutions, like internal apps. As little coding as possible.

Getting started is very easy. Start your cloud environment or docker container and off you go.

What I really like is that you can organize your models into folders and subfolders. Also the auth mechanism is very advanced, both on model and on field level.

But I also find myself struggling with some very trivial use cases. Most thinks do work, but it is just a bit hard to find the proper solution.

One of the scenarios is where I have a form, and one field should be filtered based on the value of another field. Like first you select a category, and then options in the subcategory field should be limited to the current selected category.

We need 3 models:

A model called ‘category’ with input field ‘name’. Just like that. A model named ‘sub category’ with input field ‘name’ and many-to-one field ‘category’. I set the interface

Now we want a third model that acts as the form we are interested in called. Suppose we have a beach_event form with a name, a category and a subcategory. Once we selected the category, we only want to show the subcategories belonging to the selected category.

For this we add a input called ‘name’. A many to one called ‘category’. We select collection ‘category’ and for the Interface display template we select ‘Name’ so that we select by name, not by id.

The last field is ‘sub category’. Here we do the same as for ‘category’. Only this time we add a Filter to the field:

So here Category – > ID means the category M2O field within subcategory and { category }} relates to the input on the field. You don’t get any options what to select. You can also select current user, or current date filters.

Now whenever we first select a Category in the form, the subcategories are filtered by category.

By the way, another solution would be to build your own frontend and use Directus only as api. In that case, this would be trivial. But for some use-cases I want to code as little as possible.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *