I have a collection with few datasets on one page. I used the wix built in but that is making my website slow to fetch so can some one help me filter datasets like in the picture below using code? I am new to code but can someone help me with the exact solution to this?
This little example shows you how to set a filter programmatically, …
import wixData from 'wix-data';
$w("#myDataset").setFilter( wixData.filter()
.startsWith("lastName", "D")
.ge("age", "21")
);
- Do not forget to put all your code into → onReady()-code-section
- Do not forget to add onRady()-code-part when working with datasets.
There are even more points to take care of when working with code and generating filtration.
Learn step by step.
By the way…
a) ge stnds for GREATER THAN…
b) startsWith, i think you will recognize this filter-functionality on your own.
c) there are of course even some more options you can filter for…
Hi @russian-dima , thank you or taking out the time to provide me this, I can understand this part, but I just need a little more clarity on -
how we can filter this dataset based on another dataset added on the page?
Like right now we are filtering on the basis of content we have in a collection of #dataset1 but I want to filter from #dataset2 lets say, so a connected #dataset2 item doesn’t show an item which #dataset1 is showing.
Do we have a solution for that?
Do we have a solution for that?
If you are just using all the setup-options inside the property-panel (options) given by the dataset - → i do not know if it will be possible to genrate your wished function.
But if you use CODED-VERSION - → Then i can tell you that absolutely EVERYTHING is possible.
Ok, let’s say you have 2-DATASETS.
And you want to have your second DATASET be filtered by an selected ITEM of DATASET-1 ???
Which would be your steps?
- First defining the triggering-event - → when does the actions starts?
- After action started waht to do? → FILTERING ACTION.
- After FILTERING-ACTION you get some results of DATASET-1.
- Taking the gotten RESULT and start the second FILTERING-PROCESS on DATASET-2.
- Get RSULTS of DATASET-2, by a item-filtration of DATASET-1.
In velo-code-language:
$w.onReady(()=>{console.log("Here everything starts!");
$w('#dataset1').onReady(()=>{console.log("Dataset-1 is ready!");
$w('#dataset2').onReady(()=>{
console.log("Dataset-2 is ready!");
let currentItemData = $w('#dataset1').getCurrentItem();
console.log("Selected-Item-Data: ", currentItemData);
//----------------------------------------
$w("#dataset1").setFilter(
wixData.filter()
.startsWith("lastName", "D")
.ge("age","21"))
.then((res) => {
console.log(res);
console.log("Dataset filtered now");
//Does --> "res" gives you any results?
//Not sure if it does!
//If not you will have to go another way.
// Then you will have to use Wix-Data-API in your part-1-code.
You need at this point the results of first filtering process, which you will be able to use for the second filtering process.
//SECOND FILTERING-PROSESS..
$w("#dataset1").setFilter(
wixData.filter()
.startsWith("lastName", "D")
.ge("age","21"))
.then((res) => {console.log(res);})
.catch((err)=> {console.log(err);});
});
});
});
});
Something like this. This code is just a quick coded EXAMPLE-CODE.
Maybe it even will not work - - > You will have to modify and optimize it.
My advice - → If you really want to code flexible features and functions, just use Wix-Data-API, without any help of any DATASETS.
Hi @russian-dima , Can you help me personally with WIX DATA API? I need some urgent help with it or if you can explain?
If you need personal help, you can contact me private.
You will be able to find my email on my PROFILE.
Got your message → will reply you soon😉