[Solved] How do I get row number from Airtable?

My app allows users to view or sell items for reuse. In the home screen, all the rows from Airtable are displayed in a ListViewer showing the title of the posts. I’m working on a search function where the user inputs a string and filter through all the rows to only display rows with that title in a ListViewer. It works fine, but when the user clicks on a title to open up the next screen with the post details, I was passing the index of the listViewer but what I need to do is pass the row id that matches that post. I’m not sure how to do that, can you look at my code?

Thanks,
Quinn

Hi, @qaburns014w! :wave:

When you apply any filter, the list-viewer shows only the supported items - ex. 20 from a list of 100.
If you click on any of those, index will range from 1 - 20 & not the item’s native index. So, we need to keep track of the native indexes.

Native index = row no. of the item.

To do so, we will make the normal list a numbered list by attaching the item’s native index in start of it. And then, when any item is clicked (doesn’t matter if the list is filtered or not), the item’s native index would be it’s starting no. (we’ll crop it).

First try this idea yourself, and then reply with the result here :+1:
Thanks! :blush:

i assume your rowId is a column in your table. then a block like below can obtain the value of that column:
image

however if, by rowId, you mean the unique row number assigned by airtable (during table creation), then Kartik’s trick (very clever) will work like magic!

2 Likes

@manyone can you produce a working example with our blocks?

I thought that rowNum only took an integer value. What you return could be anything. The issue with that being, there could be double of that anything. Because a list may have items from multiple data sources all in one, I’m wondering if this code works.

I didn’t think that when you add an item into a list, that it also carried over the row or item from whence it came

@kartik14’s suggestion is good. @qaburns014w, there are various ways of doing this. Another efficient/effective way to do this will be to use an auto incrementing number. or row _key

when you pull data from your table, put the items from column ‘_key’ into 1 list. put the items from your desired column in another. When you click on an item, the index will correspond with the key from the same row in the _key list you just made.

Now, get column key without filtering, and save to alist. now, in this liist, find the first occurence of the _key from the step above. these blocks would be your row number.

What if the list have duplicate items and the user wants the second one?

Thanks! :blush:

because if column key is always being incremented, it never duplicates. therefore it may look like this

row, key, animal, date born, name
1, 23, cat, 3/14/15, jon
2, 24, dog, 3/15/17, jake
3, 33, cat, 3/15/17, jon
4, 35, horse, 3/18/17, noName

assume this is a subset of a larger set of data
key list: 1: 23, 2: 24, 3: 33, 4: 35
name list: 1: Jon, 2: jake, 3: Jon, 4: noName

this way, if you click on the first Jon, you would only get info from that row. then, if you look up the corresponding key to the name, you would get the row number

On screen load
get column "Keys"
        set var.AllPossibleKeys = [green data event block]


when user click.ListItem
        set var.KeyToMatch = in list 'key list' get # [index from listviewer event block]

        set var.RowNum = in list [var.AllPossibleKeys] find first occurrence of [var.KeytoMatch]

i stand corrected.

the solution i offered works only for an UNFILTERED list view. it’s the typical way of obtaining any other column from the row that corresponds to item selected from the clicked list viewer.

but it wouldn’t work when the list viewer contains filtered rows.

Hi, @manyone! :wave:

Did you try my idea? It should surely work for both filtered / un-filtered list. :+1:

Thanks! :blush:

1 Like

I understand what you are saying but I am not quite sure how to code it. Any chance you can look at my blocks above and help?

1 Like

Please see this post @qaburns014w

3 Likes

This worked! Thank you

2 Likes

Hi, @qaburns014w! :wave:

Please mark @jared’s post as Solution :white_check_mark: since it solved your problem.

Thanks a lot!
Happy Thunking! :tada:

1 Like

2 posts were split to a new topic: How to Filter data from Airtable

Hello works for you? Can you share the blocks, Thanks

1 Like