document.addEventListener( 'jet-smart-filters/inited', function( initEvent ) {
console.log( 'filters init' );
} );There is a global JS object JetSmartFilters that gets properly inited after jet-smart-filters/inited event
document.addEventListener( 'jet-smart-filters/inited', function( initEvent ) {
console.log( JetSmartFilters );
} );Some properties/methods of JetSmartFilters object that might be useful when developing some custom solution
in it, by the key than consists of provider/queryId, all filter goups are stored
document.addEventListener( 'jet-smart-filters/inited', function( initEvent ) {
console.log( JetSmartFilters.filterGroups );
} );FilterGroup object will be described later in this document.
apply( method = 'ajax' ) to apply filters
resetFilters() to reset all group filters
filterGroup.filters contains an array of all filters
To change and apply filter: (suppose I have a filter one of the values of which is 4)\
JetSmartFilters.filterGroups['jet-engine/filt1'].filters[0].setData(4);
JetSmartFilters.filterGroups['jet-engine/filt1'].filters[0].wasСhanged();
JetSmartFilters.filterGroups['jet-engine/filt1'].apply();event bus with publish/subscribe methods
example:
ajaxFilters/updated
document.addEventListener( 'jet-smart-filters/inited', function( initEvent ) {
//see all events used by JetSmartFilters
console.log( JetSmartFilters.events.channels );
//do something on ajaxFilters/updated event
JetSmartFilters.events.subscribe( 'ajaxFilters/updated', function( provider, queryId, response ) {
console.log( provider, queryId, response );
} );
} );method to get filters within a certain element
example:
there is a container with class filters1, that have some filters in it
document.addEventListener( 'jet-smart-filters/inited', function( initEvent ) {
console.log( JetSmartFilters.findFilters( jQuery( '.filters1' ) ) );
} );jQuery( '#select-filter1 .jet-select__control' ).val( 52 ).trigger( 'change' );