Skip to content

Instantly share code, notes, and snippets.

@Mohsin-Shakeel
Last active February 22, 2025 12:57
Show Gist options
  • Save Mohsin-Shakeel/3aaca038132f3cb035cf5dd7b6f984b3 to your computer and use it in GitHub Desktop.
Save Mohsin-Shakeel/3aaca038132f3cb035cf5dd7b6f984b3 to your computer and use it in GitHub Desktop.
Refresh Gutenberg Listing grid Widget on Button Click - Jet Engine
document.addEventListener("DOMContentLoaded", function () {
let refreshButton = document.querySelector("#refresh");
let listing = document.querySelector("#topics");
// Refresh Function
function reloadListingGrid(widget) {
const jetListingItems = widget.querySelector(".jet-listing-grid__items");
const navData = jetListingItems.dataset.nav;
try {
const args = {
handler: "get_listing",
container: jQuery(widget),
masonry: false,
slider: false,
append: false,
query: JSON.parse(navData).query,
widgetSettings: JSON.parse(navData).widget_settings,
};
window.JetEngine.ajaxGetListing(args, function (response) {
if (response.success && response.data.html) {
widget.innerHTML = response.data.html;
// Reinitialize JetEngine handlers if needed
window.JetEngine.widgetListingGrid(jQuery(widget));
window.JetEngine.initElementsHandlers(jQuery(widget));
}
});
} catch (error) {
console.error("Error processing listing grid:", error);
}
}
// Trigger For Refresh
refreshButton.addEventListener("click", function () {
console.log("Reloading listing grids...");
reloadListingGrid(listing);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment