I have a table that shows a table full of data. I wanted to have every alternate row with a different background. If one of my columns had a number sequence, I know what to do. But if I do not have a column that has a number sequence, how to do it? Or is there a way of generating a sequence of numbers that starts with 1, and ends in the total numbers of rows in the table?
At the moment, a Data Template doesnât know to which Row of the data source it corresponds, unless that Data Source has an explicit âRow Numberâ / âIndexâ value in one of the fields / columns.
Do not use the HCMS automatic index as you wonât be able to change them (easily), you need an explicit field.
It is in our roadmap to add this information natively to all data sources (including when applying a filter), but most likely not in our short-term roadmap.
The only solution for now is indeed to have the numbers from 1 to N as a field in your data source.
You can then use a custom converter such as
if(INPUT % 2)
"#ff0000" //color for even rows
else
"#00ff00" //color for odd rows
I did it earlier differently and it worked. In my source (baserow.io) I had an auto-number column, based on a similar formula that you wrote, it worked. Unfortunately, when I sort my source the auto-number column is also sorted. Have a look at the screenshots.
Sort by name has the auto-number correct.
Sort by Level has the auto-number mixed.
Hi @ahmed, Iâve had to do this for leaderboards in the past.
I just put in the busy work time to create rectangles behind each of the rows. Then I assigned the rectangles visibility to the number of records on the page, so if they filtered they would disappear.
For example, a rectangle behind row 3 would be bound to total records, with a custom converter INPUT>3. Repeat. Repeat. Repeat. Itâs a brute force way to do it, but it works.
On and one small update to this - once you make the first rectangle, just Ctrl+D to duplicate it so the binding stays, then all you have to do is change the converter and position it. Goes much faster.
What I did was to create two different rectangular backgrounds. as you can see from the attached image above. I place them on top of each, and binded the visibility to the row number using a simple formula (the same as the one Seb added). It works if the view is based on the name. But if the view is based on the level, it does not work so well. It is not a deal breaker, though.
I would have liked a feature where I can add a label to the collection, give it a value of 1, then add a custom script ++INPUT which will increment this label value.
Yup, agreed. If you try to connect the row highlights with the data, it will get out of sync. So in some way you need to âfake itâ by putting something behind the table rows.
I tested another idea that may work a little better. Create a âdummyâ excel doc that is only used for row-highlights, and put it behind your actual data collection. With some simple rules, you can tell it to follow the actual data just like they are together.
Itâs not a perfect solution, but maybe it can spark some additional ideas. I also run into this issue a fair amount, so I also was curious about better ways to approach it.
I made a quick video you can watch HERE. Let me know what you think.
How cool is that of you Alex. To take the trouble and create a video is beyond expectation. You are very generous. Thank you for the tip. I wanted to run away from Excel, but it seems to be the best possible option. In my Experience, I do not need even to filter the Excel file. Thank you once again.
P.S, if you ever make it to Singapore or Malaysia, a few meals are on me.
Youâre very welcome! Iâm so glad that it was helpful!
I feel ya on Excel, but I do still love it in certain scenarios. Iâm often swearing at it and praising it in the same breath.
Itâs been YEARS since I was in Singapore and would love the opportunity to go back sometime (I know itâs the main tourist thing, but that fountain show in the middle of the city is amazing). With little kids right now, I need to wait a little while until they can handle such a long flight. But someday I will take you up on that offer. Same to you if you visit Minnesota, USA! Or drop me a message if youâre going to any of the big digital signage events - Iâm trying to get out more.