Events and custom methods for Advanced widgets

Registering event handlers and methods for Advanced widgets

You can override some behaviour of the widget with your own methods or get notified of certain events.
Those overrides works on the same way as defining options

The next options can be added to the script:

Example:

window._sn.searchpages.push({ 
engineid: '-insert-your-engine-id',
renderPagination: function (page, totalRecords, itemsPerPage)
{
/* insert your code here */
}
});


The following methods have been provided as an override:

 

Show / hide loader

Use those events to make your own loading animation to inform visitors the input is being handled.


Usage

showLoader: function () { /* insert your code */ },
hideLoader: function () { /* insert your code */ },

Facets

Get selected facets

If you have implemented your own way of handling facets then its needed to override this method to your needs

Usage

getSelectedFacets: function () { 
/*
insert your code here :
return array with ids like var selectedFacets = [];
*/},

 

Event notifications

Get notified when the widget will start rendering the search results.

beforeRenderResponse: function (data, initial) { },

Get notified when the widget is ready with rendering the search results.

afterRenderResponse: function (data, initial) { },


Notifies before search operation begins.

beforeSearch: function(term){},


Notifies after search operation has ended.

afterSearch: function(term){},


Notifies after search operation has ended but not on every typed character. 

afterSearchDebounced: function(term){},

Rendering HTML without using template engine

If you have your own template engine in place or you want to disable certain methods you need to override these methods

renderPagination: function (page, totalRecords, itemsPerPage) { },
renderResultItem: function (item) { },
renderFacetGroup: function (facetGroup) { },
addActiveFacetGroupItems: function (facetGroup) { },
renderResultHeader: function(data) {}

Or override the following method to fully intercept the rendering process

renderResponse: function (data, initial) { },

Searching

With the beforeSearchAfterRestoreFromUrl function you can pre-set values for the search. 

beforeSearchAfterRestoreFromUrl: function () {
var that = this;
var configuration = {
customFields: [
{
mode: 0,
name: 'pagetype',
value: ['Blog']
},
]
};
that.SetConfiguration(configuration);
},

With the afterInit function you can also configure and trigger a search after the first initialization. 

afterInit: function () {
var that = this;
if (that.IsInitialRequest()) {
var configuration = {
customFields: [
{
mode: 0,
name: 'pagetype',
value: ['Blog']
},
]
};
window.sp = this;
window.sp.SetConfiguration(configuration);
window.sp.TriggerSearch();
}
}

Spatial

You can configure spatial settings by adding one of the following settings to the settings variable mentioned in the code above.

With the orderByDistance you can configure the results by distance from the given latitude and longitude.

Usage:

orderByDistance: { lat: 52.150673, long: 5.384752 },

With the withinRadius you can configure which results are returned based on the given latitude , longitude and radius(km).

Usage:

withinRadius: { lat: 52.150673, long: 5.384752, radius: 15 },



Templates