Showing Related Data in Fabrik
Have you ever wanted to show data on a different table that is related to the data on another table in a Joomla site using Fabrik? For instance, let’s say you have a list of members in a race club and a list of races they have completed. This is a very common one-to-many relationship, and it’s easy to display in Fabrik.
Let’s jump in and show the relationship between our racers to races!
So, our objective is to show how many races our members have completed and to link to their race details. So this will be added on to our current member list:
First, let’s take a look at how we have things setup in Fabrik with our two lists. We have one Fabrik List that is the members table that shows information about the member:
And, then we have another Fabrik List that shows information about races completed, with one column that is tied to the Members table, the member name. This is the race info list:
That element that we used for the Member name on the Race information is a “databasejoin” type element.
If we take a look at the settings on that element we can see that we are connecting to the member table and only storing the member id on this race table. Basically, we are creating a one-to-many relationship between the two tables, meaning one member can have many races on the other table.
When we look at the form to add a race, we will see that the form is a dropdown to select a member name.
Now we could just put a filter on the top of the Race Info list and let people select a member in a dropdown to filter the records to only show the races for that particular member. But, we want to make it easier for them, and we want to see race counts by members on our member list page.
So, we will go
- Navigate to Fabrik>Lists
- Edit the member List
- Go to the Data tab on the left
- Select the Related Data tab up top (notice that Fabrik has auto detected the relationship for us because of the databasejoin element)
- Select to Yes under Show related data link
- Select the Yes radio button un Link to list
- Type the Heading for the column in list view (if you leave this blank it will use the list name)
Then if we return to the front end and refresh our member list, we’ll see the new column for races with the count for each member and a link to view the race details for that member.
If we click the View link, we will be sent to the Race List view pre-filtered to our member:
One more thing we might want to do is add this related data and link on the Details view on each member. If we open up the details on a member currently we do see all their information, but not the number of races or the link:
We can fix this quickly!
- Go to Fabrik>Forms
- Edit the form for Members
- Select the Options tab
- Set Show related data links to “Yes”
Now if we go back and refresh the member view you will see the Races count and view link up top:
And, tada! We now have a member details page that even shows related data on it.
Our example just used the default look and feel that Fabrik and our template CSS generated, but you can always change the look with custom CSS or even custom templates for lists or details.
Interested in learning more about Joomla and Fabrik? Check out our variety of courses about Joomla and Joomla-related topics.