Hello, I have a page with a "dataset1" (it has a sort of Category A-Z), the repeater is called"repeater2" and database called "Categories"( it is sorted by category alphabetically). The field I am trying to display has a key name of "category". I have tried many approaches and have read all of the articles I could find on the subject.
The code is as follows:
import { local } from 'wix-storage'; import wixData from 'wix-data'; import wixLocation from 'wix-location'; $w.onReady(() => { }); export function dataset1_ready_1() { wixData.query("Categories") .limit(300) .find() .then(results => { $w("#repeater2").data = Array.from(results.items.reduceRight((m, t) => m.set(t.category, t), new Map()).values()); }) }
The result are as follows: You will notice it is sorted until it reaches the 25th display on ???
It;s hard to understand what you're trying to do. You have a dataset but you don't use it, and instead you pull the data directly from the collection and then you process it in a complicated way that is not clear to outsiders.
Anyway, if you want the data to be sorted alphabetically, then add to your query:
//...code wixData.query("Categories") .ascending("category") .limit(300) .find() //code....
Hi J.D. tried code below and got the wrong results, everything is duplicate on display?:
export function dataset1_ready_1() { wixData.query("Categories") .ascending("category") .limit(300) .find() .then(res => { let items =res.tems; let categories = items.filter((o, index) => items.findIndex(e => e.category === o.category) === index); $w("#repeater2").data = categories; })
Back to first solution. Thank you for your help. Bill
Thank you J.D. Coding and testing now. Bill
J.D. Thank you Again.
I will try this code and let you know if I am successful. Your code is so much easier to understand and I appreciate that.
Kindest Regards,
Bill
J.D. If you have a easier way I am interested. I am always trying to improve my coding and I love WIX.
Kindest Regards,
Bill
J.D. Thank you for the quick response. I will try your suggestion.
Let me explain further. I am eliminating duplication of Categories with the code . I have Categories with many subcategories in the database.
For example: a Category is Bathroom has the Subcategories of Bathroom design, Bathroom installation, Electrical, Plumbing, Cabinets, Tiling, Sinks, Toilets and Bathtubs. One Category with 9 Sub Categories. I then want to display the repeater Categories alphabetically.
You can see the page on my live site at: https://www.donepronto.com/search-results.
I hope this clarifies things further.
Kindest Regards,
Bill