Skip to content

Utilities

Introduced with JavaScript library version 1.2.2

Utilities for building filters and facets is introduced into the JavaScript library from version 1.2.2.

The JavaScript library includes utilities for creating filter and facet strings that can be used with queries to panels, zones, and dynamic pages.

Filter builder

The filter builder enables the creation of filters with single or multiple attributes, value ranges, and operators. It is recommended to always instantiate a FilterBuilder object.

var fb = new window.apptus.utils.FilterBuilder();

When a filter is complete, the method toString() is used to extract the created filter string. The following example will convert a filter named myFilter to a string.

var myFilter = fb.attribute('filter attribute', 'value');
myFilter.toString();

The most basic filter possible includes one filter attribute and one value. The following example argument will create a filter with the value green for the filter attribute color. It will return the filter string color:'green' with the method toString().

var color = fb.attribute('color', 'green');

Multiple attributes can be used when creating filters. The following example argument will create a filter with the value green for the filter attributes color and title. It will return the filter string color,title:'green' with the method toString().

var color = fb.attribute(['color,title'], 'green');

Value ranges for attributes can also be expressed for single or multiple attributes. The following example argument will create a filter with a single attribute. The range has the start value 30 (from and including the start value) and the stop value 100 (to and including the stop value) for the filter attribute price. It will return the filter string price:['30','100'] with the method toString().

var price = fb.range('price', 30, 100);

The following example argument will create a filter multiple attributes. The range has the start value 30 (from and including the start value) and stop value 100 (to and including the stop value) for filter attribute price and cost. It will return the filter string price,cost:['30','100'] with the method toString().

var price = fb.range(['price,cost'], 30, 100);

Parameters for true and false can be added to a range argument to include or exclude the start and stop values from the range. The range argument defaults to true for both start (from and including) and stop (to and including) values if parameters are omitted.

var price = fb.range('price', 30, 100, true, false);
//returns price:['30','100') with the method toString().

var price = fb.range('price', 30, 100, false, false);
//returns price:('30','100') with the method toString().

var price = fb.range('price', 30, 100, false, true);
//returns price:('30','100'] with the method toString().

The filter builder can also use logical filter expressions to combine or exclude filters using AND, OR, and NOT.

var and = fb.and([color, price]);
var or = fb.or([color, price]);
var not = fb.not(color);

Facets builder

The facets builder enables the creation of filters with single or multiple attributes, value ranges, and arrays. It is recommended to always instantiate a Facet object.

var facet = new window.apptus.utils.Facet();

When a facet is complete, the method toString() is used to extract the created facet string. The following example will convert a facet named myFacet to a string.

var myFacet = facet.add('facet attribute', 'value');
myFacet.toString();

The most basic facet possible includes one facet attribute and one value. The following example argument will create a facet with the value green for the facet attribute color. It will return the facet string color:green with the method toString().

var facet.add('color', 'green');

Value ranges for facets can also be expressed for single or multiple attributes. Value ranges for facets have a start value that is from and including the start value, and a stop value that is to and including the stop value.

The following example argument will create a facet with a single attribute. The range has the start value 30 and the stop value 100 for the filter attribute price. It will return the facet price:['30','100'] with the method toString().

var facet.addRange('price', 30, 100);

Arrays and strings can also be used as a second parameter for facets. The following example will create a facet with the values red and orange for the facet attribute color. It will return the facet string color:red|orange with the method toString().

var facet.add('color', ['red', 'orange']);
Facets can be together with an add operator. The following example will chain a single value facet with the value red for the facet attribute color with a facet with the value nike for the facet attribute brand. It will return the facet color:red,brand:nike with the method toString().

var facet.add('color', 'red').add('brand','nike');

Chaining facets with the same facet attributes will create a facet just as an array would. The following example will chain a single value facet with the value red for the facet attribute color with a facet with the value orange for the facet attribute orange. It will return the facet color:red|orange with the method toString().

var facet.add('color', 'red').add('color','orange');

Chaining is value type independent and can combine arrays and strings into facets. The following example will chain a facet with the array values red and orange for the facet attribute color. with a facet with the value nike for the facet attribute brand. It will return the facet color:red|orange,brand:nike with the method toString().

var facet.add('color', ['red','orange']).add('brand','nike').toString(); 
×
Copyright

This online publication is intellectual property of Voyado Lund AB. Its contents can be duplicated in part or whole, provided that a copyright label is visibly located on each copy and the copy is used in conjunction with the product described within this document.

All information found in these documents has been compiled with utmost attention to detail. However, this does not guarantee complete accuracy. Neither Voyado Lund AB nor the authors shall be held liable for possible errors or the consequences thereof.

Software and hardware descriptions cited in these documents might be registered trademarks. All trade names are subject to copyright restrictions and may be registered trademarks. Voyado Lund AB essentially adheres to the manufacturer’s spelling. Names of products and trademarks appearing in this document, with or without specific notation, are likewise subject to trademark and trade protection laws and may thus fall under copyright restrictions.

CLOSE