Pritbor Team
01/29/2025, 11:20 PMconst handleSelectAllCheckboxes = async () => {
const renderState = search.renderState[indexName];
const nbPages = renderState?.pagination?.nbPages || 1;
const currentPage = renderState?.pagination?.currentRefinement || 0;
let allIds = [];
for (let page = 0; page < nbPages; page++) {
search.helper.setPage(page);
const results = new Promise(resolve => {
search.helper.once('result', resolve);
search.helper.search();
}); // I am stuck here.
console.log(results);
allIds.push(...results.hits.map(hit => hit.id));
}
// Remove duplicates and store in `selectedIds`
selectedIds = [...new Set(allIds)];
// Restore original page
search.helper.setPage(currentPage).search();
// Show all checkboxes in current page as ticked
document.querySelectorAll('#hits .row-checkbox').forEach(checkbox => {
checkbox.checked = true;
});
// Show checkbox to select all in current page as ticked
const selectAllCurrentPageCheckbox = document.getElementById('select-all-checkboxes-in-current-page');
if (selectAllCurrentPageCheckbox) {
selectAllCurrentPageCheckbox.checked = true;
selectAllCurrentPageCheckbox.indeterminate = false;
}
// Sync with Livewire
$wire.$set('checked', selectedIds);
console.log('Selected IDs:', selectedIds);
console.log('Total selected:', selectedIds.length);
};