DataSet Filter not working

I have two DataSets which I’m filtering, but only one returns something. Does anyone have any idea as to why? Here is the code:

import wixData1 from “wix-data”;
import wixData2 from “wix-data”;
import wixUsers from ‘wix-users’;

$w.onReady(function () {

// Retrieve the user's login e-mail 
let msg = wixUsers.currentUser.getEmail() 
	.then((email) => { 
		$w("#txtMail").text = email; 

		// Filter DataSet1 ( **THIS ONE WORKS!** ) 
		$w("#ds1").onReady(() => { 

			$w("#ds1").setFilter(wixData1.filter() 
					.eq("email", $w("#txtMail").text) 
				) 
				.then(() => {}) 
				.catch(() => {}); 
		}); 

		// Filter DataSet2 ( **THIS ONE DOESN'T WORK!** ) 
		$w("#ds2").onReady(() => { 

			$w("#ds2").setFilter(wixData2.filter() 
					.eq("email", $w("#txtMail").text) 
				) 
				.then(() => {}) 
				.catch(() => {}); 
		}); 
		
	}); 

});

Are you sure the first one works? I don’t think you’re importing wixData correctly. You should only need to import it once a import wixData from ‘wix-data’;

Then you should be able to create both filters using wixData.filter().

From my understanding you don’t need to import WixData twice… just import it once and with

import wixData from “wix-data”;

and change your wixData1 and wixData2 references to wixData

I already tried using only one wixData object, but it didn’t work. I have the first DataSet bound to a table and the table filters out correctly. The other DataSet is connected to an image object and two textfields, but it doesn’t return anything. I tried retrieving the number of records returned by the DataSets. The first one returns 2, the other one 0.

import wixData from “wix-data”;
import wixUsers from ‘wix-users’;

$w.onReady(function () {

let msg = wixUsers.currentUser.getEmail() 
	.then((email) => { 
		$w("#txtMail").text = email; 

		//  **WORKS** 
		$w("#ds1").onReady(() => { 

			$w("#ds1").setFilter(wixData.filter() 
					.eq("email", $w("#txtMail").text) 
				) 
				.then(() => {}) 
				.catch(() => {}); 
		}); 

		//  **NOT WORKING** 
		$w("#ds2").onReady(() => { 

			$w("#ds2").setFilter(wixData.filter() 
					.eq("email", $w("#txtMail").text) 
				) 
				.then(() => {}) 
				.catch(() => {}); 
		}); 
		
	}); 

});

could you try to refresh the ds2?

.then(() => {
$w(“#ds2”).refresh();})

How many records does the second dataset have if you don’t filter it?

Tried refreshing as well, Tom, but to no avail. I’ve been going nuts with it for the past three days! Sam, the DataSet has 3 records before filtering, 0 afterwards and, yes, I’m sure the filter value is correct.

I’ll tell you what I’m trying to do, maybe there’s another way around it. I have a user profile page. Based on his login email, I fetch it from the UserProfile and Courses DataSet. I have a table linked to the Courses DataSet and it updates automatically once I set the filter. I also have two TextFields and an Image object, all linked to the other DataSet, which should display name and last name, as well as the student’s image. But this filter doesn’t seem to do the job.

Have you cheked whether the field name in ds2 is really “email”? That cost me hours once just to realise that one column of my ds had started with a capital letter instead of a small one :0

I finally figured it out! It was all in the Databases Permission settings! Incredible, no warning from the system.

Thanks guys for your help! :slight_smile: