Search in more then one column

Hi Yevhen,

So i tried everything you suggested except the repeaters (but I will - i just need to read more about it) and i want to say THANK YOU for all the great guidance! All of it works exactly as you say.

I will end up leaving the search box in the directory that links to the dedicated search page with the results already filteed and linked

You have no idea how happy all of this made me :slight_smile:

If you want to see all your code working here are the links:

https://gotitag.wixsite.com/travelmonth/copy-2-of-family-directory-search

https://gotitag.wixsite.com/travelmonth/FamiliesProfiles

Again a million thanks. I honestly think you are the best at helping people in this forum, clear and always correct information!

Gotita

I have one last request… :slight_smile: can you help me figure out how to return an message if the search word is not found in the datababse?

thank you!!!

Hi Gotita,

I am glad to be of help :slight_smile:

Hi Gotita,

Regarding showing a message when there are no search results.

  1. Add an element or group of elements that will be shown to the user if there are no search results. In my example, I added a simple text with the ID noResultsMessage . The element(s), as the results table, should be located right below the search box (i.e. they will overlap in Editor).
  2. Make the element(s) hidden on load (in Properties panel).
  3. Check out the following code example:
import wixData from 'wix-data';
import wixLocation from 'wix-location';

$w.onReady(() => {
  $w('#dataset1').onReady(async () => {
    const { q = '' } = wixLocation.query;
    $w('#SearchBox').value = q;

    if (q !== '') {
      await search(q);
      await handleSearchResults();
    }
  });
});

export async function SearchBotton_onclick(event, $w) {
  const { value } = $w('#SearchBox');
  if (value !== '') {
    await search(value);
    await handleSearchResults();
  }
}

async function search(query) {
  await $w('#dataset1').setFilter(
    wixData
      .filter()
      .contains('location', query)
      .or(wixData.filter().contains('state', query))
      .or(wixData.filter().contains('city', query))
      .or(wixData.filter().contains('titleListing', query))
  );
}

async function handleSearchResults() {
  const resultsTable = $w('#resultsTable');
  const noResultsMessage = $w('#noResultsMessage');

  if ($w('#dataset1').getTotalCount() > 0) {
    await noResultsMessage.hide();
    await resultsTable.show();
  } else {
    await resultsTable.hide();
    await noResultsMessage.show();
  }
}

Regards,
Yevhen

Hi again!

Thank you again! it works perfectly :slight_smile: So exciting!!!

Gotita

Hi Gotita,

You are welcome! :slight_smile:

Hello Yevhen, I have few questions and let me know if you are available.
Thank you

Hello Cristina,

Go ahead, ask your questions. Me or someone else will respond you.