Select Text from Filtered Collection

Hello,

I have an 85% working code but I am struggling to figure out how to return “wixData.filter” results, instead of just the first row from a collection.

  1. This is meant to search if todays date is between the dates in Collection Column 1 (ID: fromDate ) and Column 2 (ID: toDate ).

  2. Once it finds the correct row, it filters the collection to that row. It is supposed to then return filtered text from the 3rd Column (ID: name2 ) to a simple, front end, text box.

Is there a way for this to return the 3rd column filtered text (instead of only the first row like it is doing now)? There should always be a single filtered row.

$w.onReady(function () {
    $w("#dataset1").onReady( () => {
        let d = new Date();   // get today's date
        d.setHours(0,0,0,0);  // clear out the time
        $w("#dataset1").setFilter(wixData.filter() // start filter
          .lt("fromDate", d)                  // fetch date column1
          .or(                               //or
              wixData.filter().gt("toDate", d) //fetch date column2
            )
        )
            .then( () => {                   // start text results
                wixData.query('ThisisaCollectionName')
                    .find().then(results => {
                     console.log(results)
                        let todaytext = results.items[0].name2;
                        $w('#text50').text = todaytext
                    });
            });

    });
});

Any ideas or suggestions would be greatly appreciated.

Thank you.

Hi @jeffc ! There is a way to return the filtered text from the 3rd column (ID: name2) of the single filtered row, instead of just the first row. You can modify the code to use the wixData.filter().eq() method to filter the collection based on a specific value in the fromDate and toDate columns. Good luck!

Hello,

Thank you for replying. I attempted to translate .eq into the filter but I seem to be getting no results from the dataset when I query it. Any ideas? Here is what I came up with:

$w.onReady(function () {
    $w("#dataset34").onReady( () => {
        let d = new Date();  	// get today's date								
        d.setHours(0,0,0,0);  	// clear out the time								
		let flag1 = wixData.filter().gt("fromDate", d) 				// fetch date column1           
		let flag2 = wixData.filter().lt("toDate", d) 				// fetch date column2
    
 
			$w("#dataset34").setFilter(wixData.filter().eq("flag1", "flag2"));  //apply filter results to Collection

wixData.query("SceanrioDeskAdmin")	   // query filtered collection and return result						
				.find()
				.then(results => {
                	console.log(results)
                    let todaytext = results.items[0].name2;				// get text from third column "name2"
                   	 	$w('#text50').text = todaytext					// apply text, after filter, to frontend text box
            });
	});
});