wix website velo code. Need to add function. When selecting different filters or…
- User
wix website velo code. Need to add function. When selecting different filters or searching, Pagination needs to revert back to 1 of x, instead at remaining at current page. Here is the current code: import wixData from "wix-data";
w.onReady(function () { // Function to execute the search function executeSearch() { let searchValue = w("#searchInput").value.trim(); $w("#dataset1022").setFilter( wixData.filter().contains('name', searchValue) ); }
// Function to reset the search bar, clear the query, and reset highlighted filter tags function resetSearch() { // Clears the input field $w("#searchInput").value = ""; // Resets the dataset filter to remove any search query $w("#dataset1022").setFilter(wixData.filter()); // Reset all filter button highlights resetAllButtonHighlights(); } // Function to reset all filter button highlights function resetAllButtonHighlights() { filterButtons.forEach((buttonId) => { $w(buttonId).style.backgroundColor = '#0c3c60'; // Reset each button to the original color }); } // List all your filter button IDs here const filterButtons = [ '#tagAll', '#tagCategory1', '#tagCategory2', '#tagCategory3', '#tagCategory4', '#tagCategory5', '#tagCategory6', '#tagCategory7' ]; // Add click event to each filter button filterButtons.forEach((buttonId) => { $w(buttonId).onClick(() => { resetAllButtonHighlights(); if (buttonId === '#tagAll') { $w("#dataset1022").setFilter(wixData.filter()); // Reset to show all } else { highlightAndFilter(buttonId); } }); }); function highlightAndFilter(selectedButtonId) { // Highlight the currently clicked button $w(selectedButtonId).style.backgroundColor = '#FE6F5E'; // Set highlight color // Determine filter criteria based on the button clicked let filter = wixData.filter(); // Start with an empty filter switch (selectedButtonId) { case '#tagCategory1': filter = wixData.filter().eq('type', 'Food & Drinks'); break; case '#tagCategory2': filter = wixData.filter().eq('type', 'Retail & Grocer'); break; case '#tagCategory3': filter = wixData.filter().eq('type', 'Personal Services'); break; case '#tagCategory4': filter = wixData.filter().eq('type', 'Animal Services'); break; case '#tagCategory5': filter = wixData.filter().eq('type', 'Health, Wellness, & Human Services'); break; case '#tagCategory6': filter = wixData.filter().eq('type', 'Business, Professional, & Financial Services'); break; case '#tagCategory7': filter = wixData.filter().eq('type', 'Home, Auto, & Commercial Services'); break; } // Apply the filter to the dataset $w('#dataset1022').setFilter(filter); } // Event listener for the search button click $w("#searchButton").onClick(() => { // Execute the search executeSearch(); // Reset the search bar and highlighted tags after performing the search resetSearch(); }); // Event listener for the "Enter" key press in the search input field $w("#searchInput").onKeyPress((event) => { if (event.key === "Enter") { // Execute the search executeSearch(); // Reset the search bar and highlighted tags after performing the search resetSearch(); } }); - Assistant
- User
"Make sure to replace #pagination with the correct selector for your pagination component." - elaborate
- Assistant
In Wix Velo, you use a unique identifier called an element ID to interact with components on your web page through code. Each element you add to your page, including pagination components, has an ID that allows you to access and manipulate it via Velo's JavaScript.
Finding the Pagination Component ID
- User
If the intent is to always have a change of filters, or a search, result in a reset to pagination1, page 1, of any set, then what would the final code be?
- Assistant
- User
Where can i find the correct ID for the pagination element?
- Assistant
To find the correct ID for the pagination element in your Wix site, you will need to use the Wix Editor to identify and verify the ID. Here’s how you can do it:
Steps to Find the Pagination Element ID
-
Open the Wix Editor:
- Log into your Wix account and open the specific site you want to edit. Click on “Edit Site” to open the Wix Editor.
-
Locate the Pagination Element:
- Navigate to the page where your dataset and pagination are implemented.
-
- User
the only way to view pagination setting is through an on/off toggle in the "Table Layout" menu. The pagination on this table is baked in. No ID is displayed. Where else can this ID be located
- Assistant
In Wix, if you are using a table component that has built-in pagination and does not expose a direct ID for the pagination feature, you might need to take a different approach to control or interact with it. Here are some methods to address this issue:
Exploring Alternative Solutions
- User
"When you apply a filter directly to the dataset using setFilter(), pagination should reset due to the change in dataset items. Ensure your dataset's settings in the Editor are configured to display data as desired." how can I do this in the previously existing code?
- Assistant
- User
Provide full code with "Invoke $w("#dataset1022").refresh();" for testing
- Assistant
- User
The pagination issue does not correct, and remains in it's previous state despire filter / search changes
- Assistant
- User
After remving pagination form the desktop editor on Wix, the pagination on mobile still remains - why
- Assistant