Dear all,
I have no experience in coding in WIX (basic knowledge in coding in general). I have spent a lot of time viewed many tutorials on youtube, and this forum but was not able to find a solution for my problem.
-
I have a static database I populate manually with different companies. For each company I have the following columns. I am using Tags a lot because it is easy to insert them and avoid typo errors:
-
Category: there are 5 fixed tags. Each company has only one tag
-
Country: Each company has one or several country tags (when they are present in different countries)
-
SDGs: each company has several sdgs assigned to them. Each tag is only a number.
-
Other fields are of course company name, description… all text fields
-
In my page, there’s a repeater I want to use to display the results of the users’ search.
Currently I have attached the database to my page and the single repeater is displaying the whole database.
Now I would like to be able to let any user (navigating on this page) to perform a search on all the fields above using the simplest solution and minimalist display -
SDGs: This is my most urgent issue. How to let the user select one or multiple SDGs on the webpage and display the results in my repeater. I guess if I can figure this out I will be able to deal with Country and Category fields. I saw in this forum someone posting about using an Array, then loop it for each line, to store each Company’s tags, and compare it with the array obtained by the user. Is it the best and simplest solution? I don’t know how to code it on the page end and database end and compare them.
-
All text fields: Same question : how to code it.
Questions recap: I don’t want to make this complicated and would like to avoid any dynamic page. I have currently attached my database to the page and using the database icon and Settings I was able to display my entire database using a repeater. So I would just like to use codes and this single repeater as it seems easier to manage.
-
What type of search ( checkbox, or search, or drop down list) ) should I use on my page in order to get the correct query data format to query the tags inside the static database knowing that it can target columns with one tag or multiple tags ? I guess there are limitations. Could you please share the exact code I should try? It is a bit difficult to figure it out by myself. I am not sure my current code for multiple checkbox is the correct solution especially it will look very heavy on the page.
-
Is there a type of search (checkbox, or search, or drop down list) that can address both tags type and text type columns in my static database?
-
There are a few post in this forum with detailed examples using $w. It seems it has been removed from the recent version of Wix so how to code it now?
Thanks a lot in advance for your time! Your help means a lot to me!
PS: I saw that in a static database, there is a limited number of columns so I am unable to create a dedicated column for each SDG (1 to 17)…
This is as far as I could get: I am stuck at this line
$w("#repeater1").data = filteredResults;
, there is an error message in the console saying
Wix code SDK error: The data parameter that is passed to the data method cannot be set to the value . It must be of type array.
I can’t figure out how to force the repeater to use what is returned from the filterResults function
Entire code
import wixData from 'wix-data';
//////////////////////// INITIATE THE filteredDatabase ARRAY
let filteredDatabase = [];
$w.onReady(function () {
});
//filter function to be called by
function filterResults(selectedSDG){
wixData.query("ListOfCompanies")
.hasSome("sdg", selectedSDG)
.ascending("title")
.find()
.then( (results) => {
if(results.items.length > 0) {
console.log("Results >0. matching database result:", results)
console.log("1st item in result:",results.items[0])
let items = results.items;
let firstItem = items[0];
let totalCount = results.totalCount;
let pageSize = results.pageSize;
let currentPage = results.currentPage;
let totalPages = results.totalPages;
let hasNext = results.hasNext();
let hasPrev = results.hasPrev();
let length = results.length;
let query = results.query;
} else {
console.log("filterResults function: NO matching result:");
// handle case where no matching items found
}
console.log("filterResults function: filtered table refore return results:", results);
//At this point of the code, the results returned are correct! The static database is well filtered.
return results;
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
}
//This is the multiple choices checkbox for SDG selection
export function checkboxSdg_change(event) {
// Get the values of all the ticked checkboxes in that group. This is working. I have the right values in the console
let selectedSDG = event.target.value;
console.log("the user has selected the following SDG numbers:",selectedSDG)
const filteredResults= filterResults(selectedSDG);
console.log("chekboxSdg function: filteredResults returned from filterResult function value check:", filteredResults);
// Now, filter the database and display result. This is not working and returns and error see above
//set the repeater. THIS IS WHERE THE ERROR IS
$w("#repeater1").data = filteredResults;
//setting the repeater elements
$w("#repeater1").onItemReady(($w, itemData) => {
console.log("checkboxSdg_change results titles : ",itemData.title);
$w("#text179").text = itemData.title;
$w("#image44").src = itemData.logo;
})
}