Filter Drop-down Results [Please Help]

My dynamic category page includes a list of tasks that should be grouped by Client Name. Users are able to search a table of tasks by task title, or they can use a drop-down to view by task status. I found the code for this functionality on this youtube video .

I love the way it works, except for the fact that for some reason, when users select from the list of options, the results pull in tasks their tasks, but it also displays the tasks of other clients. Obviously, my goal when creating the dynamic category page, was that the results would be filtered by client name. I’m guessing that something in the code for the search bar and/or drop-down, is impacting the category page functionality.

I’ve pasted all of the code I’m using on the page below. Can anyone help me figure this out?

$w.onReady(function () {
$w(“#button59”).target = “_self”;
$w(“#button57”).target = “_self”;
$w(“#button58”).target = “_self”;
$w(“#image9”).target = “_self”;

});
import wixData from “wix-data”;
$w.onReady(() => {
wixData.query(‘Key’)
.find()
.then(res => {
let options = [{“value”: ‘’, ‘label’: ‘Any Status’}];
options.push(…res.items.map(status => {
return {‘value’: status.value, ‘label’: status.label};
}));
$w(‘#iStatus’).options = options;
})
});

let lastFilterTitle;
let lastFilterKey;

let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iTitle’).value, lastFilterKey);
}, 200);
}

function filter(title, taskStatus) {
if (lastFilterTitle !== title || lastFilterKey !== taskStatus) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘title’, title);
if (taskStatus)
newFilter = newFilter.eq(‘taskStatus’, taskStatus);
$w(‘#dynamicDataset’).setFilter(newFilter);
lastFilterTitle = title;
lastFilterKey = taskStatus;
}
}
export function iStatus_change(event,$w) {
filter(lastFilterTitle, $w(‘#iStatus’).value);
}

import {local} from “wix-storage”;

const linkField = “link-TaskDatabase-title”; // replace this value

$w.onReady(function () {
$w(“#dynamicDataset”).onReady(() => {
const numberOfItems = $w(“#dynamicDataset”).getTotalCount();

$w("#dynamicDataset").getItems(0, numberOfItems) 
  .then( (result) => {  
    const dynamicPageURLs = result.items.map(item => item[linkField]); 
    local.setItem('dynamicPageURLs', dynamicPageURLs); 
  } ) 
  .catch( (err) => { 
    console.log(err.code, err.message); 
  } ); 

} );
} );

Hey Juanita,

it’s awesome that you have this problem, because just yesterday we published a new feature for filtering a dataset by current logged in user.
If the collection records are being inserted by the desired client => this filter will do the job for you.
If this is not the case, I will find a different way to help you. But first let’s see if this feature is enough to solve your problem.

Article for how to use the filter: https://support.wix.com/en/article/how-to-filter-a-page-based-on-the-currently-logged-in-user

Good luck!

Cheers,

Thanks for the feedback, Mor! I actually input many of the tasks myself. Therefore, this option would be great for me IF . . . rather than filtering by owner, I could first filter by one particular field in the collection, and then another. In this case, I NEED to filter by Client Name and it would be nice to have the ability to allow the logged in user to view all tasks for their company, and to also filter the tasks by the “Assigned To” field.

Just to be clear, I currently have one collection (TaskDatabase) which includes all tasks for all clients. The Category page was designed to display tasks according to the client. The hyperlink is set up to look like this: https://www.writeitrightsite.com/TaskDatabase/Client-Name/{Client-Name}

My issue is that when users attempt to filter their tasks by status, all tasks matching the selected status, regardless of which client they belong to, are listed on the table. I need to ensure that one client cannot view another client’s tasks.

Hello! I’m still hoping for some help with this. Is there anyone who can help me add some code to my page so that my table displays only those tasks which belong to a particular client? I have several datasets attached to this page. One in particular is the Client Database dataset. I need the tasks displayed on the table, to be only those tasks that are assigned to the client who is logged in.

I’ve made updates to the code since my first post. Here’s the code currently being used on the page:

// Import statements
import wixData from “wix-data”;

$w.onReady(function () {
// All code runs here after page is loaded

});

export function filterDropdown_change() {

$w(“#taskDataset”).onReady( () => {

if ($w(‘#filterDropdown’).value === ‘Any Status’) {
$w(“#taskDataset”).setFilter( wixData.filter() );
} else
{
$w(“#taskDataset”).setFilter( wixData.filter()
.eq(“taskStatus”, $w(‘#filterDropdown’).value)

)
.then( () => {
console.log("Dataset is now filtered by " + $w(‘#filterDropdown’).value);
} )
.catch( (err) => {
console.log(err);
} );
}
});

}