Dataset Filtering to Show Certain Fields

Hello! I am trying to display member profiles on my page but because my members have many different data fields, I only want certain profiles to appear on certain pages. When I found out that there was a dataset filtering function, I was very excited. But later realized that the filtering functionality is very limited, from what I see?

For example, each added filter would be an (“and”) filter but I want to filter if one data point contains this or another data point contains this, so this would be a “or” filter. In the attached screenshot, I am trying to add members to a page where their University input contains “Toronto” either in their first University field or their second University. As long as one of their university field contain the word “Toronto”, I want to grab it in. I’m not sure if this is available at the moment but would be very helpful!

Hi,

You can filter the table using regular JS code for more complex filtering scenarios. You can check out the filtering example here .

Have a good day,
Tal.

Hi Tal,

Thanks for your response! I tried using the JS code in the other forum but have a hard time seeing how it would apply for me as I do not have dropdown boxes and want the lines in the table to appear as they are.

Would it be better to use a “contain” code? Can you help guide me further with the code I have? I’m quite lost.

let originalRows = [];

$w.onReady(function () {
$w(‘#dataset1’).onReady(() => {
originalRows = $w(‘#table1’).rows;
});
});

function filterTable() {
let newRows = originalRows;
const university1 = $w(‘#table1.university1’).value;
const university2 = $w(‘#table1.university2’).value;
if (university1 && university1 !== ‘Toronto’) {
newRows = newRows.filter(item => item.Field === university1);
}
if (university2 && university2 !== ‘Toronto’) {
newRows = newRows.filter(item => item.Field === university2);
}

$w('#table1').rows = newRows; 
filterTable(); 

}

Hi,

I created a filter query to match your requirements:

import wixData from 'wix-data';
$w.onReady(function () {
	$w("#dataset1").setFilter(wixData.filter()
			.contains("university1", "Toronto")
			.or(wixData.filter()
			.contains("university2", "Toronto")
		)			
		)
		.then(() => {
			console.log("Dataset is now filtered");
		})
		.catch((err) => {
			console.log(err);
		});
});

Hi Ido,

Thanks for your response! I actually would need to create a master list where you can filter the list to see the filtered results using a dropdown. I’m also wondering how I can connect the dropdown with my table under. Also I noticed that the dropdown contain duplicates of one field, how do I prevent this? Can you check my code please?

Hi guys, following up on my previous post - I’m actually trying to combine a master collection on the “Alumni” page so that people can find the university alumni by choosing from a dropdown. I tried to follow the instructions on this page (Velo Tutorial: Adding Collection Data Search Functionality | Help Center | Wix.com) but it’s missing some steps which I think can be crucial in my code working. I also tried to follow this video but the code on screen is different from that article above (CMS (Formerly Content Manager): About Your Collection Fields | Help Center | Wix.com).

Some question I have are:

  • How is the table connected to the dropdown?
  • How do I make sure there are no duplicates in the dropdown?
  • And when a dropdown is selected, how does one filter the value in both university1 and university2 fields?