How to show only pre-selected items from local database in dataviewer-list/-grid?

to every row of my database i have a “datafield” named “seleced” - with this “flag =0/1)” i want to “select” or “deselect” each item before showing it in a dataviewer-list / -grid.

item_selected

how do i have to code this with blocks, that only items with flag = 1 are shown in dataviewer-list / - grid?

many thanks in advance for every proposal!

1 Like

Data Viewer Lists can only show the entire contents of a data source. So in order to filter them, you have to duplicate the data source and filter it. You can have a second data source where you delete all rows and then create rows and populate them from the data in your original data source but only if a condition is true (selected = 1). You’ll need to loop through the original data source to do this.

1 Like

many thanks for your advice - it saves me very much time!

1 Like

Check this

https://x.thunkable.com/projectPage/5fb9fb1dbfeb240011084d78

I do this, but it is quite slow as I have 40 rows.

1 Like

Yes @codeswept
This would be slow for two obvious reasons.

  • You are evaluating the list of values block with every iteration of your loop which means you are reading the database 40 times in your example.
  • You are retrieving the value of a cell in every iteration which again means reading the database 40 times.

[Edit]
See my version of your code which should run much faster.

4 Likes

Thank you so much for this! No wonder it was taking 2 minutes to filter my DB each time.

1 Like

Yep, switching from a stored variable to an app variable is also going to be faster. If you need to use a stored variable, assign its value to an app variable before using the app variable in the loop.

3 Likes

Great, thanks for the suggestions!

1 Like

Thank you very much for your version - i tried to test it out but could not succeed,
i build an item_list with 5 datasets (see screenshot)
item_list

with blocks i want to “deselect” one dataset (= “duck”) ot my itemList …

but it shows me all datasets of my item_list

many thank in advance for your help!

1 Like

Have you tested it on your mobile?

yes, i test it with thunkableApp on my iphone 12 and on android tablet, same result - all 5 items are dsplayed …

1 Like

here is link to project …

https://x.thunkable.com/copy/999b2893f211d5d49b767b487e82127a

1 Like

check this

I made it highlight the line but the logic is the same.

i replace your

“higlight the line”

with

"set Data_Viewer_List1`s LayoutWrapper for … “s Visible to false”

and now it works fine …

thank you so much!

1 Like