Question: Change hitsPerPage when filtering ?
See original GitHub issueHello,
It is possible to update hitsPerPage defined in Configure widget when filtering on a “Menu” widget like the demo : https://www.algolia.com/search/
My code :
index.js
import algoliasearch from 'algoliasearch/lite'
import instantsearch from 'instantsearch.js'
import searchBox from './Searchbox'
import menu from './Menu'
import { advert, bpDoc, demarche, post, tribeEvents, uptUsers } from './Indices'
const searchClient = algoliasearch('XXXXXX', 'XXXXXX')
const search = instantsearch({
indexName: 'wp_searchable_posts',
searchClient,
})
search.addWidgets([
searchBox,
menu,
advert,
post,
])
search.start()
Menu/index.js
import { menu } from 'instantsearch.js/es/widgets'
export default menu({
container: '#algolia-menu',
attribute: 'post_type',
sortBy: ['name:asc'],
templates: {
item(item) {
const { url, label } = item
switch (label) {
case 'advert':
return `
<a href="${url}">
<span>Petites annonces</span>
</a>
`
case 'post':
return `
<a href="${url}">
<span>Actualités</span>
</a>
`
default:
return `
<a href="${url}">
<span>${label}</span>
</a>
`
}
},
},
})
Indices/index.js
import { configure, hits, index } from 'instantsearch.js/es/widgets'
import { hitsTemplate } from './templates'
import { customConfigure, customPagination } from './../customWidget'
// Custom Post Type : advert
export const advert = index({
indexName: 'wp_posts_advert',
})
.addWidgets([
hits({
container: '#algolia-hits-advert',
templates: {
item(hit) {
return hitsTemplate(hit)
},
empty: `<style>#advert { display: none; }</style>`
}
}),
configure({
hitsPerPage: 4,
}),
])
// Custom Post Type : post
export const post = index({
indexName: 'wp_posts_post',
})
.addWidgets([
hits({
container: '#algolia-hits-post',
templates: {
item(hit) {
return hitsTemplate(hit)
},
empty: `<style>#post { display: none; }</style>`
}
}),
configure({
hitsPerPage: 3,
}),
])
Thanks for help.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
hitsPerPage API parameter - Algolia
By clicking Accept, this grants permission to track your data. You can change/withdrawal by clicking on Cookie Settings in the website footer.
Read more >InstantSearch.js custom widget increase returned results
When the page loads, it automatically makes a request and retrieves the default results with no query. We have more than 500+ results...
Read more >Learn Change Management Online | Coursera
Change Management courses from top universities and industry leaders. Learn Change Management online with ... 931 results for "change management". Filters ...
Read more >Implementing the Pagination Component - Educative.io
... a pagination toolbar that allows the user to change the current page. ... By default the Pagination component renders 20 hits per...
Read more >Resources - BioLogos
As their faith and science questions go unanswered, young people are leaving ... Filter (1) ... Billions of Years, Amazing Changes: The Story...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Two other options:
refine
function when it needs to changeI found a way but it’s very dirty 😄 In my
renderConfigure
function I check ifhierarchicalFacetsRefinements
is not empty and the value of the attribute of the container defined in thecustomConfigure
options, then I refine my hitsPerPage.If you have a sexier way to do this, feel free to share it 😄 Anyway thanks for help.