# Sorting database

**URL:** <https://forum.wixstudio.com/t/sorting-database/14260>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [December 15, 2017, 4:49pm UTC](https://forum.wixstudio.com/t/sorting-database/14260 "2017-12-15T16:49:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-hanelt](https://avatars.discourse-cdn.com/v4/letter/b/f9ae1b/32.png) [@ben-hanelt](https://forum.wixstudio.com/u/ben-hanelt)\
**Post date:** [December 15, 2017, 4:49pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/1 "2017-12-15T16:49:15Z")

</div>

I am trying to show a database entry on a page. The entries (rows) include a “year” column (going from 1925 to 2018). I can SORT the database by the year, but the sorting 1) is not displayed on the site, and 2) does not get retained by the database. For whatever reason, the database reverts back to 1983 as the first row. I have made changes in Sandbox before Sync, and I have made changes to the Live database; each time I have pressed save. I have also clicked on “Edit Live Database”; here the sorting is correct and stays correct. However, when I go back to sandbox/live, the rows have again rearranged; starting with 1983.

---

<div class="post-metadata">

**Author:** ![giri-zano](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/giri-zano/32/80469_2.png) [@giri-zano](https://forum.wixstudio.com/u/giri-zano)\
**Post date:** [December 15, 2017, 6:26pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/2 "2017-12-15T18:26:37Z")

</div>

Ben, I am not quite sure if I understood you correctly, but are you sure you are not mixing up a collection with a resultset (queryresult). The first is the raw, underlying database in an unsorted way, the second is the result of a query, sorted how you want. This is a COPY (more or less) of the DB and the DB itself will not be sorted.

---

<div class="post-metadata">

**Author:** ![ben-hanelt](https://avatars.discourse-cdn.com/v4/letter/b/f9ae1b/32.png) [@ben-hanelt](https://forum.wixstudio.com/u/ben-hanelt)\
**Post date:** [December 15, 2017, 10:51pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/3 "2017-12-15T22:51:07Z")

</div>

Giri, thanks for writing. Ok, I think that I understand. However, I am not sure that I have discovered in Wix how to get a search result from a DB to show up in a table form. When I insert a table (Insert: lists and grids), the only choice I have is to “Connect to Data”. This choice allows you to specify which DB and which columns. No other options are visible. How would I show the results of a query instead? I am sure that this is easy, but being 48 new to Wix, it is escaping me.

---

<div class="post-metadata">

**Author:** ![shlomi-shemesh](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@shlomi-shemesh](https://forum.wixstudio.com/u/shlomi-shemesh)\
**Post date:** [December 16, 2017, 7:54am UTC](https://forum.wixstudio.com/t/sorting-database/14260/4 "2017-12-16T07:54:59Z")

</div>

Ben,

check out gallery to display the results and [Displaying Database Content on a Dynamic Item Page | Help Center | Wix.com](https://support.wix.com/en/article/tutorial-using-a-dynamic-item-page-to-display-content) to display a single result for further details. another cool option is using [https://support.wix.com/en/article/about-repeaters](https://support.wix.com/en/article/about-repeaters) it will make your site more stunning than a simple table result. you can use code to create whatever you want given the ability to query your db and use display components

good luck!  
Shlomi

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [February 27, 2018, 11:36pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/5 "2018-02-27T23:36:42Z")

</div>

Shlomi…how do you get a search box to work with repeater? I have tried using code as shown in a tutorial video, but as soon as you type in a search, the repeater disappears with no results showing…and no idea how to use a simple box and button approach.

This is the code I tried to use:  
[https://www.youtube.com/watch?v=Hx7\_8-lRsW0&feature=youtu.beI](https://www.youtube.com/watch?v=Hx7_8-lRsW0&feature=youtu.beI)

---

<div class="post-metadata">

**Author:** ![shlomi-shemesh](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@shlomi-shemesh](https://forum.wixstudio.com/u/shlomi-shemesh)\
**Post date:** [February 28, 2018, 7:06am UTC](https://forum.wixstudio.com/t/sorting-database/14260/6 "2018-02-28T07:06:31Z")

</div>

can you share your site and where you got so far?

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [February 28, 2018, 1:08pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/7 "2018-02-28T13:08:34Z")

</div>

Shemesh, here is link to page: [https://www.ourozarks.com/Ozarks](https://www.ourozarks.com/Ozarks)

Here is code thus far:  
import wixData from “wix-data”;

let debounceTimer;  
export function iTitle\_keyPress(event, $w) {  
if (debounceTimer) {  
clearTimeout(debounceTimer);  
debounceTimer = undefined;  
}  
debounceTimer = setTimeout(() =\> {  
filter($w(“#iTitle”).value);  
}, 200);  
}

let lastFilterTitle;  
function filter(title) {  
if (lastFilterTitle !== title) {  
$w(“#Ozarks”).setFilter(wixData.filter().contains(“Place”, title));  
lastFilterTitle = title;  
}  
}

And here is screen shot of database. Have reverted to simplicitiy to try to work the bugs out and connected only the Place column. I have found that by deleting ! in the conditional expression highlighted below, it takes away the blanking out of results, but it actually then gets no results. Leaving code as == shows a hint that expect ===, but replacing with === gets no results and leaves screen as is. So guessing somehow everything tied to this line or other line of filter. But their code seems to work fine at this point of tutorial.  
**if (lastFilterTitle !== title) {**

![](https://us1.discourse-cdn.com/wix/original/3X/2/d/2dac54560f95d12455a8b910ea5eb780cae92e74.jpeg)

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [February 28, 2018, 1:13pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/8 "2018-02-28T13:13:54Z")

</div>

![](https://us1.discourse-cdn.com/wix/original/3X/4/8/4800ae79786507ac6cd16eb9e1cafa0df6c95f81.jpeg)  
The warning is Parameter event is never used (their code has this showing as well at that point). The only thing I can think of is how they have their repeater set up…like so many of these tutorials, they do not show the “pre-setup”…they already have buttons and repeater in place. So a setting off? They have a connection in place that I do not. I have tried also connecting to datasets, not connecting, etc in an attempt to replicate to no avail. I used repeater from the List & Grid add an item. It appears to be one they used…but?

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [February 28, 2018, 1:20pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/9 "2018-02-28T13:20:33Z")

</div>

Layout of page in editor

 ![](https://us1.discourse-cdn.com/wix/original/3X/e/b/ebdcc110816be9015d97e182a08a70aa88b9fbbf.jpeg)

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [February 28, 2018, 1:33pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/10 "2018-02-28T13:33:38Z")

</div>

Since writing this, have done some more playing around. Changed the id of the textbox that connects to Place. It had id of text17. I changed to place thinking perhaps that was where supposed to read. When I went to search, it no longer disappeared but no results. Changed all back, but now staying as not blanking out, but no results being made per search. Have to start believing the issue may be with the repeaters provided in Lists & Grids not playing nice with code?

---

<div class="post-metadata">

**Author:** ![shlomi-shemesh](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@shlomi-shemesh](https://forum.wixstudio.com/u/shlomi-shemesh)\
**Post date:** [February 28, 2018, 3:16pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/11 "2018-02-28T15:16:31Z")

</div>

Hi,

thanks for sharing. the issue turned out to be quite simple - the use of the column display name rather than its key. another thing is the use of the component value (text) and not the component for the query filter

```javascript
export function button2_click(event, $w) {
	console.log($w("#iTitle"));
	$w("#dataset1").setFilter(wixData.filter().contains("title", $w("#iTitle").value));
}

```

 ![](https://us1.discourse-cdn.com/wix/original/3X/1/2/123a1ea7b787e4fefbae14e3d71156e0490199c3.png)  
good luck,  
Shlomi

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [February 28, 2018, 3:21pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/12 "2018-02-28T15:21:09Z")

</div>

Shlomi, you are showing a click event rather then keyPress as I am trying to use

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [February 28, 2018, 3:27pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/13 "2018-02-28T15:27:35Z")

</div>

Oh my…that fixed it!!! Appreciate this so much!!! and yes, works as keyPress!! I really could add a few more !!!

---

<div class="post-metadata">

**Author:** ![shlomi-shemesh](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@shlomi-shemesh](https://forum.wixstudio.com/u/shlomi-shemesh)\
**Post date:** [February 28, 2018, 3:57pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/14 "2018-02-28T15:57:08Z")

</div>

Jeff,

there is currently a known issue with onkeypress value used for filtering, until we resolve it, please prefer the search button

shlomi

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [February 28, 2018, 5:10pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/15 "2018-02-28T17:10:38Z")

</div>

onkeypress working for this wonderfully

---

<div class="post-metadata">

**Author:** ![shlomi-shemesh](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@shlomi-shemesh](https://forum.wixstudio.com/u/shlomi-shemesh)\
**Post date:** [March 1, 2018, 6:25pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/16 "2018-03-01T18:25:49Z")

</div>

Jeff,

works because of the throttler you set up, glad it is working for you 😉  
regarding the image click, it is a bit hidden but where you connect the image to data you also have link to…  
choose your dynamic page of the single item

good luck,  
Shlomi

 ![](https://us1.discourse-cdn.com/wix/original/3X/0/a/0ad827a3b220e79463e2b332afbd18422d8ada5e.jpeg)

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [March 1, 2018, 6:28pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/17 "2018-03-01T18:28:33Z")

</div>

Realized my error as soon as I clicked out…tried to do delete that comment but too late. Loving the search I have set up.

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [March 1, 2018, 6:33pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/18 "2018-03-01T18:33:04Z")

</div>

If you happen to know…if a person has several options available but want to show only those inputed how?  
Example: colors blue green yellow red  
Person in form input selects blue yellow that goes to database fields for each. But in profile you only want it to show the blue yellow, without the loss of space of a spot for green and red…in other words a continuous list.

---

<div class="post-metadata">

**Author:** ![shlomi-shemesh](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@shlomi-shemesh](https://forum.wixstudio.com/u/shlomi-shemesh)\
**Post date:** [March 2, 2018, 1:48pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/19 "2018-03-02T13:48:34Z")

</div>

Hi Jeff,

the example you gave uses terms too specific to your domain, can you please elaborate some more. i didnt understand what you are trying to achieve

Shlomi

---

<div class="post-metadata">

**Author:** ![jeff-haskins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff-haskins/32/1864_2.png) [@jeff-haskins](https://forum.wixstudio.com/u/jeff-haskins)\
**Post date:** [March 2, 2018, 3:06pm UTC](https://forum.wixstudio.com/t/sorting-database/14260/20 "2018-03-02T15:06:14Z")

</div>

Shlomi,  
I believe I figured out how to make this work by creating a field that the person can enter their own info (but do so with preferred terminology list. I want to show on a profile or dynamic page the choices they have made, be searchabe…but to set up a separate field for each causes an issue in setting up the field on dynamic pages…if they choose only nonfiction and horror, then you have blanks showing where historical fiction, romance and true crime fields are…unless way to have some sort of generated field based on form input that takes out the blanks so you can have one searchable field that has all the terms chose listed and not the ones they did not chose.

![](https://us1.discourse-cdn.com/wix/original/3X/0/d/0d8b48d064490b312cfb995c13e90236210f3ce6.jpeg)  
On side note, when you set up a dynamic page for member profiles (set to public viewing), and your dynamic page url is set with ID on end…is that a clickable/searchable link in search engine?

[Next page](https://forum.wixstudio.com/t/sorting-database/14260.md?page=2)
