Sitecore 9.0.2 SXA 1.7.1 search load more
Sitecore 9.0.2 SXA 1.7.1 search load more.
Same conditions as in this blog.
Modified component-search-load-more.js - SearchLoadMoreView:
Same conditions as in this blog.
Issue:
We are using SXA the default search control, and in one of the cases we had even more than two searches in one page, and noticed that the search Load More keeps disappearing and appearing many times while loading and sometimes it does not show even that the Page Size is less than the returned search items count, which caused a wrong behavior.
We made sure that the signatures for each search is different but the issue was still there.
We had to make some changes to js file component-search-load-More.js to solve this issue and check Signature before hiding or showing the Load More component.
We had to make some changes to js file component-search-load-More.js to solve this issue and check Signature before hiding or showing the Load More component.
Original component-search-load-more.js - SearchLoadMoreView:
SearchLoadMoreView = Backbone.View.extend({
initialize : function () {
var dataProperties = this.$el.data(),
that = this;
if (dataProperties.properties.searchResultsSignature === null){
dataProperties.properties.searchResultsSignature = "";
}
if (this.model) {
this.model.set('sig', dataProperties.properties.searchResultsSignature.split(','));
}
XA.component.search.vent.on("results-loaded", function (results) {
var sig = that.model.get('sig'),
i;
for (i = 0; i < sig.length; i++) {
if (results.pageSize >= results.dataCount) //in case if results.offset and/or results.searchResultsSignature are undefined
{
that.$el.hide();
} else {
if (sig[i] === results.searchResultsSignature)
if (results.offset + results.pageSize >= results.dataCount) {
that.$el.hide();
} else {
that.$el.show();
}
}
}
});
………………...
Modified component-search-load-more.js - SearchLoadMoreView:
SearchLoadMoreView = Backbone.View.extend({
initialize : function () {
var dataProperties = this.$el.data(),
that = this;
if (dataProperties.properties.searchResultsSignature === null){
dataProperties.properties.searchResultsSignature = "";
}
if (this.model) {
this.model.set('sig', dataProperties.properties.searchResultsSignature.split(','));
}
XA.component.search.vent.on("results-loaded", function (results) {
var sig = that.model.get('sig'),
i;
for (i = 0; i < sig.length; i++) {
if (sig[i] === results.searchResultsSignature)
//in case if results.offset and/or results.searchResultsSignature are undefined
if (results.pageSize >= results.dataCount)
{
that.$el.hide();
}
else
{
if (results.offset + results.pageSize >= results.dataCount) {
that.$el.hide();
} else {
that.$el.show();
}
}
}
});
………………...
Lastly, you can refer to Sitecore docs to check the official document on how to set up the search here also there are those YouTube videos that will help learning SXA
Comments
Post a Comment