Sort table by user email

That is not what I am looking for. Another user creates the document and the person trying to read it have different owner IDs. Unless there is a way to assign a different owner id when the record is created, this will not meet my requirement.

Hi Alex:

Have you posted all of the code for your site?

Also I noted this comment:

type mismatch of some kind? does it matter that this is a reference field and the key in the referenced collection is a different name of the key in the parent collection?
It may be worth exploring this further. You might need to go back to the table that is connected to $w(‘#dataset1’) and examine the field name and field key values. Normally when you create a column in a data collection you enter the field name and the Editor generates a key field based on the field name. So for example if you added a field called First Name then the editor generate a field key firstName . The field key is what you need to be using when accessing data collection properties in returned results.

Now here’s the thing. If you decide to rename the column by changing the field name the field key WILL NOT change. So in the example above if you decide you prefer to have Parent First Name as the new field name the field key will remain as firstName . So if the column you have set the field name as email to in the database was originally Email Address and you renamed it to email at some point then the field key would be emailAddress and not email .


If you are using the wrong key then you will get an error.

One other thing you can do is dump the dataset in the onready function like this to see what it is you think you are filtering:

$w('#dataset1').onReady(() => {
    $w('#dataset1').getItems(0, $w('#dataset1').getTotalCount())
    .then((results) => {
        console.log('===============> Dumping dataset1 <===============');
        console.log(results);
        console.log('===============> End dump dataset1 <===============');
        return wixUsers.currentUser.getEmail();
    })
    .then((email) => {
        console.log(email, 'here is the email being sent to filter');
        return $w("#dataset1").setFilter(wixData.filter()
              .eq("email", email) );
    })
    .then( () => {
        console.log("Dataset is now filtered");
    })
    .catch( (err) => 
        console.log(err);
    });
}

Then post the results if you can’t see any issues.

Other than that without seeing all of the page code (if this isn’t it all) or access to the page to examine in the browser console then helping you figure this out will be tough.

Cheers
Steve

Thank you for the response. The field key is correct. I am filtering against a column that is referenced. The referenced column had a key of title and the column in the database had a key of email. I fixed this and made sure that they both match. Did not fix my problem.

this is the only code currently on the site.

@whitneyas Hi Alex. Several thoughts here.

The dataset1 you are using is empty so it’s hard to see what impact it is having on your page.

Based on your other comments it sounds like you have two datasets involved in the output you are seeing. The different out put you are seeing may have nothing to do with the filter or be a side effect of the filter failing.

The most important thing is how you have wired up the reference field. A reference field needs to be populated with the ‘_id’ value of the table row it is referencing. You can’t pick a random column such as ‘title’ or ‘email’. You have to think of each reference as being the whole row of a table. The only unique value in a Rowe entry of a data collection isn’t its ID. This is accessed using the ‘_id’ field key in Code.

I would reread the data collection docs on reference fields if I was you.

The value that is displayed in the reference field comes from the primary field of the specific item in the referenced collection. The actual value that is stored in the database is the ID of the referenced item (in other words, the value in the ID system field of the referenced collection).

Also you need to look at why the table is empty. It may be a side effect of the incorrect use of the reference field or not syncing all sandbox dat collections to live. You may also have a permissions problem on one or other of the data collections that stops access to the dataset.

Hope this helps
Cheers
Steve

If the dataset is empty where is the data coming from when it works for the student column?

I can’t answer that as I don’t have access to your page and how you have wired up the datasets. All I can tell you is what I see and that is that your console.log shows an empty items array when you getItems. Do you have a filter applied somewhere on the dataset?

Try changing the getItems call for debugging to this.

$w(‘#dataset1’).setFilter(wixData.filter())
.then(() => {
    return $w(‘#dataset1’).getItems(0,  $w(‘#dataset1’).getTotalCount());
})
.then((result) => {
...

This will clear any existing filters before loading the dataset contents.

If this still returns an empty result set then you have data collection config issues that can only be debugged in the Wix Editor.

Hope this helps.
Steve

It appears using the reference field to pull the emails to filter against will not work because of it using the ID’s. This helps me see a way forward at least for now. Thank you for you help and time.

Hi Alex, did you manage to work around around this ? I’m in need of something similar

@thecandymachinefreel Not yet. I actually just picked this back up today. It’s due in May.

Have you? :slight_smile: