Filter Dataset by Last Pay Date

Hello, here I have a code for a search bar with loading gif. Everything seems to be working fine, I would just like for our employees to initially see the items from their last pay date only. I can’t set the limit number because each employee will have a different amount of entries, if any for that pay period.

I’m then looking to incorporate a dropdown for employees to only view THEIR pay dates, not the whole dataset’s dates.

The dataset is filtered by logged in user which I’ve had difficulties putting together so any advice is appreciated!!

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

$w.onReady( function () {
wixUsers.currentUser.getEmail()
.then((email) => {
let userEmail = email; //"user@email.com"
$w(“#dataset1”).setFilter(wixData.filter()
.eq(“loginEmail”, email))
})

})

let debounceTimer;

export function searchBar_keyPress(event) {

$w('#loadingGif').show(); 

if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}

debounceTimer = setTimeout(() => { 

let SearchValue = ($w(“#searchBar”).value);
wixUsers.currentUser.getEmail()
.then((email) => {
let userEmail = email; //"user@email.com"
$w(“#dataset1”).setFilter(wixData.filter().eq(“loginEmail”, email)
.contains(‘account’, SearchValue)
.or(wixData.filter().eq(“loginEmail”, email)
.contains(‘payType’, SearchValue)
.or(wixData.filter().eq(“loginEmail”, email)
.contains(‘payDate’,SearchValue))));
$w(‘#loadingGif’).hide();
}, 200);
});
}

Hello.

You can use setSort() function of the dataset and specify criteria and field as shown in the API below:
https://www.wix.com/corvid/reference/wix-data.html#sort

Also, you can use limit() to return only the latest pay date and use other aggregations to display more content based on user interaction with your site.
https://support.wix.com/en/article/corvid-working-with-aggregations-in-the-data-api

Good luck!