Filtering Tables On Dynamic Pages

Hey everyone,

I have a dynamic page which pulls in from a database. However, i have added another data set where that data will be shown on a table on the dynamic page.

I want to filter the table results specifically for the current dynamic page. The method i tried was to use the Text that was connected to the dynmaic page data to use that as the filter for the other dataset for my table.

.contains(“businessname”, $w(“#text28”).value)

Thats the code i tried but it kept erroring :frowning:

Any advice??

Hi Tim,

What error are you getting? Please post your code.

Yisrael

Hi Yisrael,

Heres my code:

import wixData from ‘wix-data’;

$w.onReady(function () {
//Get current date
let currentDate = new Date();

//Get records with future dates compared to current date 
$w("#dataset1").setFilter(wixData.filter() 
	.ge("eventDate", currentDate) 
	.contains("resturaunt", 'Bowland Brewary') 
); 

});

Where it says ‘Bowland Brewary’ - that is just text so i can check date code, i need it to link to a ‘Text’ field (Not textbox) thats on the page which changes due to it being a dynamic page field.

The end result is a table that results change dependent on which version of the dynamic page you see.

Tim

This is the code i was trying:

import wixData from ‘wix-data’;

$w.onReady(function () {
//Get current date
let currentDate = new Date();

//Get records with future dates compared to current date 
$w("#dataset1").setFilter(wixData.filter() 
	.ge("eventDate", currentDate) 
	.contains("resturaunt", $w("#text28").Value) 
); 

});

But what error are you getting? What is the message in the developers console?

In the editor i get an error saying ‘value is undefined’ and then in preview move, i get:

Unhandled promise rejection Error: Failed to build a filter. Invalid .contains parameter value [Undefined]. .contains parameter must be a String…

I’ve managed to do it! Posting the code as it might help someone in the future:

import wixData from ‘wix-data’;

$w.onReady(function () {
//Get current date
let currentDate = new Date();
let tRecord = $w(“#text28”).text;
//Get records with future dates compared to current date and text link to title.
$w(“#dataset1”).setFilter(wixData.filter()
.ge(“eventDate”, currentDate)
.contains(“resturaunt”, tRecord)
);
});

Thnaks for your help on this!