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

**URL:** <https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987>\
**Category:** Questions about Thunkable X\
**Tags:** beginner\
**Created:** [June 14, 2021, 10:25pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987 "2021-06-14T22:25:07Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![limogopy64fbb](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@limogopy64fbb](https://community.thunkable.com/u/limogopy64fbb)\
**Post date:** [June 14, 2021, 10:25pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/1 "2021-06-14T22:25:07Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/3/b3f6c79d3823346955170ec6c9407138f9dddc40.jpeg)

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!

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 14, 2021, 10:51pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/2 "2021-06-14T22:51:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![limogopy64fbb](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@limogopy64fbb](https://community.thunkable.com/u/limogopy64fbb)\
**Post date:** [June 15, 2021, 6:46am UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/3 "2021-06-15T06:46:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 15, 2021, 7:07am UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/4 "2021-06-15T07:07:30Z")

</div>

Check this

[https://x.thunkable.com/projectPage/5fb9fb1dbfeb240011084d78](https://x.thunkable.com/projectPage/5fb9fb1dbfeb240011084d78)

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [June 15, 2021, 7:09am UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/5 "2021-06-15T07:09:39Z")

</div>

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/7/7725bf82d7521cd5a869625d0686314c32e2ace1.png)

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

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 15, 2021, 10:21am UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/6 "2021-06-15T10:21:49Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/c/5c8a64e1ae27c9819dabdf4d1279e6477ff535b5.png)

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [June 15, 2021, 12:10pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/7 "2021-06-15T12:10:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 15, 2021, 3:48pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/8 "2021-06-15T15:48:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [June 15, 2021, 4:09pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/9 "2021-06-15T16:09:25Z")

</div>

Great, thanks for the suggestions!

---

<div class="post-metadata">

**Author:** ![limogopy64fbb](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@limogopy64fbb](https://community.thunkable.com/u/limogopy64fbb)\
**Post date:** [July 1, 2021, 11:26am UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/10 "2021-07-01T11:26:53Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/4/74d505b20c7b998fa8a9a4eed48e8d91dfba3b44.jpeg)

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

 ![blocks](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/7/c7ab1c60535d2269dedfbe9027180cefb7b7cf23.jpeg)

but it shows me all datasets of my item\_list

 ![dataViewerList](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/8/f87c791794418540941b2c3cd304789584cfc1db.jpeg)

many thank in advance for your help!

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 1, 2021, 1:19pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/11 "2021-07-01T13:19:57Z")

</div>

Have you tested it on your mobile?

---

<div class="post-metadata">

**Author:** ![limogopy64fbb](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@limogopy64fbb](https://community.thunkable.com/u/limogopy64fbb)\
**Post date:** [July 1, 2021, 2:02pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/12 "2021-07-01T14:02:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![limogopy64fbb](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@limogopy64fbb](https://community.thunkable.com/u/limogopy64fbb)\
**Post date:** [July 1, 2021, 2:23pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/13 "2021-07-01T14:23:48Z")

</div>

here is link to project …

[https://x.thunkable.com/copy/999b2893f211d5d49b767b487e82127a](https://x.thunkable.com/copy/999b2893f211d5d49b767b487e82127a)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 1, 2021, 3:36pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/14 "2021-07-01T15:36:47Z")

</div>

check this

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/7/070ea161d8d9f78be63a9e0fb94ab86bd39add29.png)

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

---

<div class="post-metadata">

**Author:** ![limogopy64fbb](https://avatars.discourse-cdn.com/v4/letter/l/90db22/32.png) [@limogopy64fbb](https://community.thunkable.com/u/limogopy64fbb)\
**Post date:** [July 1, 2021, 8:55pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/15 "2021-07-01T20:55:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 1:20pm UTC](https://community.thunkable.com/t/how-to-show-only-pre-selected-items-from-local-database-in-dataviewer-list-grid/1344987/16 "2024-11-08T13:20:17Z")

</div>


