Wix website building - how to create an element (repeater) that displays on mobile but not desktop
Assistant
To create a Wix page element, like a repeater, that displays on mobile but not on desktop, you need to use the Wix Editor to control the visibility settings of your elements for different devices. Here's how you can do this:
Access Your Wix Site:
Log in to your Wix account and select the site you want to edit.
Go to the Editor:
Click "Edit Site" to enter the Wix Editor.
Add a Repeater:
User
HArd reset to pagination? get back to "1 of x" with any input of search or filter?
Assistant
User
Assistant
User
Removing the pagination from the table functions properly on desktop - but the pagination remains on mobile. How to disabe
Assistant
If you are experiencing issues where the pagination is still visible on mobile but not on desktop with Wix, you can address this by explicitly controlling the display of the pagination component using some custom code and the Wix Editor's mobile interface.
Here's how you can manage this:
Go to the Mobile Editor:
While in the Wix Editor, switch to the mobile view by clicking the mobile icon at the top of the page. This view allows you to make changes specifically for mobile devices without affecting the desktop layout.
If you haven't already added a repeater, go to the left menu, click the "+" icon (Add), and select "Repeater" to add it to your page.
Set Up the Repeater:
Customize your repeater as needed by adding items and linking it to a data collection if desired.
Switch to Mobile Editor:
In the top toolbar of the Wix Editor, click the mobile icon to switch to the mobile editing mode. This allows you to adjust how your site appears on mobile devices specifically.
Adjust Visibility Settings:
Select the repeater element. Once selected, a floating menu or a "Settings" icon may appear near the element or under the settings on the right sidebar.
Look for the "Hidden on Desktop" or "Hide on Desktop" option. Toggle this setting to hide the element on the desktop view.
Verify Desktop View:
Switch back to the desktop view by clicking the desktop icon in the top toolbar. Double-check that the repeater is hidden on the desktop version of your site.
Save and Publish:
Make sure to save your changes. Click "Save" and then "Publish" to make your changes live.
This process makes the repeater visible on mobile devices while being hidden on desktop view, allowing you to tailor the user experience for different devices. Always preview your site on both mobile and desktop modes to ensure everything looks as expected before publishing.
To ensure that any search or filter action resets your pagination to the first page, you'll typically need to include logic in your application that automatically sets the page number to 1 whenever a search or filter is applied. The approach to achieve this can vary depending on the platform or programming environment you're using. Here's a general idea of how you might implement this:
General Approach
Detect Search or Filter Action:
Add event listeners on your search input fields or filter controls. This could include text fields for searching, dropdowns for selecting filters, or checkboxes.
Reset Pagination:
Upon detecting a change in the search or filter input, reset your pagination logic to start at the first page. This usually involves setting your pagination state back to 1.
Fetch Data:
After resetting the pagination, fetch the data for the first page using the updated search or filter parameters.
Example Implementation in JavaScript (for a web application)
If you're building a web application with JavaScript, here's a simplified example using basic JavaScript concepts:
javascript
let currentPage = 1; // Default to 1
function handleSearchInput(event) {
const searchTerm = event.target.value;
resetPagination();
fetchData(searchTerm, currentFilter);
}
function handleFilterChange(event) {
const selectedFilter = event.target.value;
resetPagination();
fetchData(currentSearchTerm, selectedFilter);
}
function resetPagination() {
currentPage = 1;
updatePaginationDisplay();
}
function fetchData(search, filter) {
// Assume fetchDataFromServer is a function that fetches
// data from the server based on current search, filter, and page.
fetchDataFromServer({ search, filter, page: currentPage });
}
function updatePaginationDisplay() {
// Update your pagination display/navigation UI to reflect the reset
console.log(`Currently on page ${currentPage}`);
}
// Event listeners for search/filter inputs
document.getElementById('searchInput').addEventListener('input', handleSearchInput);
document.getElementById('filterSelect').addEventListener('change', handleFilterChange);
Key Points
Resetting Logic: Always ensure the pagination is reset to the first page (currentPage = 1) whenever a new search or filter query is detected.
Pagination UI Update: Make sure your pagination UI reflects this reset so that users get a visual cue that they're back on the first page.
Data Fetching: Ensure that any data-fetching calls take into account the current state of search, filters, and page number to fetch the correct set of records.
This general approach can be adapted for different frameworks (like React, Angular, Vue) or platforms (such as mobile app development) by incorporating similar logic tailored to the specifics of those environments.
Implement pagination reset (with no #pagination ID) to this 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)
);
}
code
// 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();
}
});
});
To implement a pagination reset in your Wix code when a search or filter action is performed, you'll want to ensure the dataset's paging moves back to the first page. Since you mentioned there's no specific #pagination element, I'll guide you on how to handle this using the Wix API with your dataset. Here’s how you can modify your functions to reset the pagination:
Modify the Code to Reset Pagination
Reset Dataset to First Page:
Use the setCurrentItemIndex method on your dataset to reset to the first item, which effectively resets pagination to the first page.
Update your Existing Functions:
Incorporate calls to reset the pagination after filtering or searching.
Here’s how you can modify your existing code:
javascript
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)
)
.then(() => {
resetPagination(); // Reset to page 1 after setting filter
});
}
// 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())
.then(() => {
resetPagination(); // Reset to page 1 after resetting filter
});
// Reset all filter button highlights
resetAllButtonHighlights();
}
// Function to reset dataset pagination to the first page
function resetPagination() {
$w("#dataset1022").setCurrentItemIndex(0);
}
// 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
.then(() => {
resetPagination(); // Reset to page 1 after resetting filter
});
} 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)
.then(() => {
resetPagination(); // Reset to page 1 after setting 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();
}
});
});
Explanation
setCurrentItemIndex(0): This method effectively moves the dataset back to the beginning, resetting to the first "page" of data.
Promising Chaining: The .then() chaining ensures that the pagination is reset only after the filter has been successfully applied or reset.
Hide Pagination on Mobile:
Check if there is a separate pagination control that is visible only on the mobile view.
Select the pagination control within the mobile view. In the properties panel, you’ll have the option to hide the component. Look for the "Hidden on Mobile" option or uncheck "Show on Mobile." This should hide the pagination on mobile devices.
Use Code to Control Display (Optional):
If the above steps don't resolve the issue, you can use code to control the display of the pagination element. Assuming your pagination element has an ID, you can use the following code snippet to hide it on mobile devices:
javascript
$w.onReady(function () {
if (wixWindow.formFactor === "Mobile") {
hidePaginationOnMobile();
}
function hidePaginationOnMobile() {
// Replace 'paginationElement' with the actual ID of your pagination control
$w("#paginationElement").collapse();
}
});
Publish Your Changes:
After making these adjustments, be sure to preview your site on mobile to ensure the pagination is no longer visible. Once confirmed, save and publish your site.
By tailoring the visibility settings for specific elements in both desktop and mobile views, you can ensure a consistent and desired user experience across different devices. When using the Wix Editor, always make sure that every change you make on mobile is tested separately from the desktop changes to ensure they reflect properly.