I’d like to display certain things on every “nth” item in a list, for example.
In a list, is there a way to know which one if the first, the second, third, etc?
Use case: I want to display certain content in between the fourth and fifth item in a list. If I knew which one is the fourth, I can add that to the display, but only show it if the item number is 4.
I’ve done this with an admob banner within a social media post feed.
Here’s how:
First, your collection of items needs a number parameter that acts as a record ID number. So we’ll name it “Post ID” in the posts collection. Each record should have a unique numerical value, preferably starting at 1, and incrementally increases by 1 for each record. So record 1’s post ID = 1. Record 2’s post ID = 2, etc.
I have a list of social media posts collection. Inside the list, add 2 input components. Name the first input “Post ID Input” and the second one “Post ID Input 2”
Add a custom formula to “Post ID Input” like “Current Post ID divided 4”. This will give you a decimal point value if the post is not divisible by 4. So if we’re on Post #5, you’d see 1.25 in that input.
Add a custom formula to “Post ID Input 2” like “Current Post ID divided by 4 minus INT(Post ID divided by 4)”. This will give you either 0 if the number is divisible by 4 and a decimal point value if it is not divisible by 4.
Add your “certain things” you want to display to the list. Set the visibility to these “things” to sometimes visible if “Post ID Input 2” is equal to 0.
Hide the inputs by putting a rectangle over them and making them fully transparent (remove background, border, and set text/placeholder text to 0 opacity).
Okay, this is a great suggestion and I see where you’re going with it. Back in my coding days, I would use the INT() function a lot to do similar things.
However, my list will never have the same items each time. Doesn’t your suggestion assume that each time my list loads, it will always start with 1, then 2, then 3, etc? My list will be a subset of records each time, often random, and shared among the audience. So, in your example, if it were a social media feed, it would be like each person seeing the feed but items in a different order or filter.
With every system I’ve worked with, I’ve been able to ascertain the row number from a query, or have been able to put a counter in the loop that can increment with each row. We can’t do that either.
This seems like an easy feature to add. This AND the adalo id number of each record. These should be available with every list.
That being said, I did come up with a way to do this randomly, but it’s far from ideal. I put a number field in the collection. When each record is created, I fill it with a random digit from 0-9 (for example). Then, when the list loads, I act upon each record that matches a random digit that I declare some other way (and change frequently). In the case of 0-9, then my special content (ad for example) does show up 10% of the time. But it’s not consistent from list-instance to list-instance. Some instances will have zero, while others have three, for example. I tested it, and when using 0-9, the content come up with 10% of the returned records. So I get the desired coverage, but only in the aggregate. And while I’m doing this nonsense, I can’t help wonder why such a great platform has such a glaring omission in functionality.
There is a ID for each record but it’s hidden for App Makers ( Not sure why ). And Victor made a feature request to make that ID Public. You can vote here :
And Steven made a component for get record ID for each record :
And this post also will be helpful about giving a Unique ID for each record :
Great! I have upvoted that feature request. Needs more votes though!
It still doesn’t help my original need for a sequential id that is list-query-specific. This is not a value from the record, but something that the query should provide dynamically.
Not sure if this is relevant - though I had this thread opened in a browser tab so decided to share some thoughts
In my opinion, with current Adalo limitations there is no “general” solution for this which works in all cases. However, there are some particular cases when something similar could be achieved with a filtered list.
Let’s assume you need to display the ad after 4th item in the list, and the query could contain various filters (e.g. item should belong to logged-in user).
A prerequisite which is mandatory is that you have some numeric ID by which this list is sorted, and these IDs are unique.
So, what approach you could use: