Wix DATA

I trying to run a search on the database on the page.

I wrote this code for the search box on the onKeypress
import wixData from “wix-Data”;

export function Iappellido_keyPress(event) {
filter($w(‘#Iappellido’).value);
}

function filter (apellido){
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘Apellido’, apellido))
}

when i go to the preview page i got the error:
Cannot find module ‘wix-Data’ in ‘public/pages/yb52p.js’
Any Clue? thanks in advance

it should be ‘wix-data’ (lower case)

  • keyPress needs a small to timeout, otherwise it won’t catch the change.

Thanks, works perfect,

Im New with this so sorry if my questions are very obvious,
Now i Execute the code OK but the page don’t show the info, i’m using a repeater on the page to display the data.

The code is:
import wixData from “wix-data”;
let debounceTimer;
export function Iappellido_keyPress(event) {
if (debounceTimer){
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
console.log($w(‘#Iappellido’).value);
filter($w(‘#Iappellido’).value);},200);
}
let lastFilterApellido;
function filter (apellido){
if (lastFilterApellido!== apellido){
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘Apellido’+‘Nomnbre’, apellido));
lastFilterApellido = apellido;
}
}

The following line doesn’t make sense:

  $w('#dataset1').setFilter(wixData.filter().contains('Apellido'+'Nomnbre', apellido)); 

because a field key in you database can’t be “ApellidoNomnbre” (all the field keys start with a lower case character.

Really Thanks, work perfect

you’re welcome :slight_smile: