Let users filter data in a table

I followed the instructions explicitly, step by step and walked through the code numerous times, yet I’m still not getting the results as explained in this tutorial.

Is there anyone that I can give access to the editor portal of my site to verify that I set up everything correctly?

Thank you,
Collin
collint202@gmail.com

Hi Colin,
You can also check out the example here regarding filtering the table data using multiple user inputs.
Note that the words in Hebrew are not related to the logic of the code.

Best,
Tal.

Hi Tal,

Good day!
Greetings from the other side. :slight_smile:
I hope you can also look at this —> https://www.wix.com/code/home/forum/questions-answers/how-to-insert-a-data-in-two-collection-from-a-form

Thank you,
Georgie

Hi Geo,
Read this thread .
Roi


Want to thank everyone for the advice and code samples. I tried a few and still no success. Could everyone give it one more look over to see where I could have gone wrong? – Thank you so much!

  1. An integer will be passed from a previous page and assigned to the variable: PrevPageVar
  2. The data stored in this variable will be compared to the data stored in a field called “Lessonid” (column) in the “Lessons” database.
  3. The code should filter so only records (rows) with the specified integer will appear in my text box named, “StoryBox”.

I actually see how there could be potential problems with the code, but I’m not too sure how to connect it all up.


let originalRows = ;
let PrevPageVar = 1;

$w.onReady(function () {
$w(‘#Lessons’).onReady(() => {
originalRows = $w(‘#Lessonid’).rows;
});
filterTable();
});

function filterTable() {
let newRows = originalRows;
const field = $w(‘#PrevPageVar’).value;
if (field && field !== “”) {
newRows = newRows.filter(item => item.Field === field);
}
$w(‘#Lessonid’).rows = newRows;
$w(“#StoryBox”).text = $w(‘#PrevPageVar’).value;
}

Any suggestions would be greatly appreciated.
Thank you!!

Ok, been working on this for the most part of today. I was able to get it to work as long as I’m querying a database field that is set to text. But, when I query a database field that is number, it doesn’t work. Here is the code that worked.: (Query database text field ‘correctAnswer’.

(Works)
export function runfilter_onclick() {
console.log (“filtering”);
$w(“#LessonsDS”).setFilter(wixData.filter().contains(‘correctAnswer’, ‘B’));
}

But, ‘lessonid’ is a number field and nothing happens.

(Doesn’t work)


export function runfilter_onclick() {
console.log (“filtering”);
$w(“#LessonsDS”).setFilter(wixData.filter().contains(‘lessonid’, ‘1’));
}

Hi Collin,
If the type of lessonid is number you should set the filter with a number value.
Like this:

$w("#LessonsDS").setFilter(wixData.filter().contains('lessonid', 1)); // instead of '1'

Good luck!
Roi

Excellent suggestion! – I gave it a try, with and with out quotation marks, neither way had any affect. Anyone else have any ideas why the code might run perfectly to query from database text fields, but not from numeric (int) fields? ( I change lessonid to a field that is text and it runs perfect) – Thanks