Introduction

The WixDataFilter functions enable you to filter and control which results are returned by a dataset when the setFilter() function is applied.

A filter is used to control which data is contained in a dataset on your page.

Typically, you build a filter using the filter() function, refine the filter with WixDataFilter functions, and then apply the filter to the dataset using the setFilter() function.

For example, the following code shows a filter on a dataset that is connected to a collection containing customer data. The filter includes only customers over the age of 20:

Copy
import wixData from "wix-data"; const customerFilter = wixData.filter().gt("age", 20); $w("#myDataset").setFilter(customerFilter);

When working with Wix app collections, check which fields can be used in a filter.

Did this help?

and( )


Adds an and condition to the query or filter.

The and() function adds an and condition to a WixDataQuery or WixDataFilter. A query or filter with an and returns all the items that match the query or filter as defined up to the and function and also match the query or filter passed to the and function.

Note that when chaining multiple WixDataFilter functions to a query an and condition is assumed. In such cases, you do not need to add a call to the and() function. For example, this query returns results where status is active and age is greater than 25.

Copy
wixData.query("myCollection").eq("status", "active").gt("age", 25);

The and() function is needed when performing compound queries. For example, the final query in this set of queries returns results where status is either pending or rejected and age is either less than 25 or greater than 65.

Copy
let statusQuery = wixData .query("myCollection") .eq("status", "pending") .or(wixData.query("myCollection").eq("status", "rejected")); let ageQuery = wixData .query("myCollection") .lt("age", 25) .or(wixData.query("myCollection").gt("age", 65)); let statusAndAgeQuery = statusQuery.and(ageQuery);

The collections referenced by both the initial query and the query passed to the and function must be the same.

The 'and()' function is designed to work with 2 or more queries or filters. If you use it on its own, it will return all the items in a collection.

Method Declaration
Copy
function and(query: WixDataQuery): WixDataQuery;
Method Parameters
queryWixDataQueryRequired

A query to add to the initial query as an and condition.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query1.and(query2);
Did this help?

between( )


Refines a query or filter to match items whose specified property value is within a specified range.

The between() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is greater than or equal to rangeStart and less than rangeEnd.

It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

If a property contains a number as a String, that value will be compared alphabetically and not numerically. Items that do not have a value for the specified property are ranked lowest.

The following types of properties can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so
    • "A" and "M" are between "A" and "Z", but "a", "m", "z" and "Z" are not.
    • "A", "M", "Z", and "a" are between "A" and "z", but "z" is not.
Method Declaration
Copy
function between(
  propertyName: string,
  rangeStart: union,
  rangeEnd: union,
): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with rangeStart and rangeEnd.


rangeStartunionRequired

The beginning value of the range to match against.


rangeEndunionRequired

The ending value of the range to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.between("age", 25, 65);
Did this help?

contains( )


Refines a query or filter to match items whose specified property value contains a specified string.

The contains() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property contains the specified string. Matching with contains() is not case sensitive, so "text" does contain "Tex".

You can use contains() with a property whose value is a String or a Reference. For properties of type reference it is recommended that you use the eq() function instead of contains(). With properties that are References, contains() matches by the ID of the referenced item as a String.

Method Declaration
Copy
function contains(propertyName: string, string: string): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with the string.


stringstringRequired

The string to look for inside the specified property value.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.contains("description", "some words");
Did this help?

endsWith( )


Refines a query or filter to match items whose specified property value ends with a specified string.

The endsWith() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property ends with the specified string. Matching with endsWith() is not case sensitive, so "TEXT" ends with "ext".

You can only use endsWith() with a property whose value is a String or Reference. When using a Reference, endsWith() matches by the ID of the referenced item as Strings.

Method Declaration
Copy
function endsWith(propertyName: string, string: string): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with the string.


stringstringRequired

The string to look for at the end of the specified property value.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.endsWith("last_name", "z");
Did this help?

eq( )


Refines a query or filter to match items whose specified property value equals the specified value.

The eq() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property equals the specified value.

It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

Matching strings with eq() is case sensitive, so "text" is not equal to "Text".

If propertyName points to a collection field of type Array, eq() includes the item as long as at least one Array element matches the specified value.

Method Declaration
Copy
function eq(propertyName: string, value: any): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with value.


valueanyRequired

The value to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.eq("status", "active");
Did this help?

ge( )


Refines a query or filter to match items whose specified property value is greater than or equal to the specified value.

The ge() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is greater than or equal to the specified value.

It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

If a property contains a number as a String, that value will be compared alphabetically and not numerically. Items that do not have a value for the specified property are ranked lowest.

The following types of properties can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so "abc" is greater than or equal to "ABC" (because of the greater than), but "ABC" is not greater than or equal to "abc".
  • Reference: Compares by the ID of the referenced item as a String.
Method Declaration
Copy
function ge(propertyName: string, value: union): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with value.


valueunionRequired

The value to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.ge("age", 25);
Did this help?

gt( )


Refines a query or filter to match items whose specified property value is greater than the specified value.

The gt() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is greater than the specified value.

It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

If a property contains a number as a String, that value will be compared alphabetically and not numerically. Items that do not have a value for the specified property are ranked lowest.

The following types of properties can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so "text" is greater than "Text".
  • Reference: Compares by the ID of the referenced item as a String.
Method Declaration
Copy
function gt(propertyName: string, value: union): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with value.


valueunionRequired

The value to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.gt("age", 25);
Did this help?

hasAll( )


Refines a query or filter to match items whose specified property values equals all of the specified value parameters.

The hasAll() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property equals all of the specified values.

Matching strings with hasAll() is case sensitive, so "text" is not equal to "Text".

If the value of the specified property is an array, hasAll() will match if there is a match in the elements of that array for all of the specified values.

You can specify a list of values to match by providing an array of String, Number, or Date types as the value parameters.

Method Declaration
Copy
function hasAll(propertyName: string, value: union): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with value.


valueunionRequired

The values to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.hasAll("sizes", [30, 38, 42]);
Did this help?

hasSome( )


Refines a query or filter to match items whose specified property value equals any of the specified value parameters.

The hasSome() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property equals any of the specified values.

Matching strings with hasSome() is case sensitive, so "text" is not equal to "Text".

If the value of the specified property is an array, hasSome() will match if any of the elements of that array match any of the specified values.

If the specified property contains multiple references, pass item IDs in the value property. In such a case, hasSome() will match if any of the multiple references match any of the specified ID values.

You can specify a list of values to match by providing an array of String, Number, or Date types as the value parameters.

Method Declaration
Copy
function hasSome(propertyName: string, value: union): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with value.


valueunionRequired

The values to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.hasSome("sizes", [30, 38, 42]);
Did this help?

isEmpty( )


Refines a query or filter to match items whose specified property does not exist or does not have any value.

The isEmpty() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is null or undefined or the property does not exist.

If the property contains any value at all for a given item, including the empty string or an invalid value, that item will match the query.

Method Declaration
Copy
function isEmpty(propertyName: string): WixDataQuery;
Method Parameters
propertyNamestringRequired

The the property in which to check for a value.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.isEmpty("bio");
Did this help?

isNotEmpty( )


Refines a query or filter to match items whose specified property has any value.

The isNotEmpty() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is not null or undefined.

If the property contains any value at all for a given item, including the empty string or an invalid value, that item will match the query.

Method Declaration
Copy
function isNotEmpty(propertyName: string): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property in which to check for a value.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.isNotEmpty("bio");
Did this help?

le( )


Refines a query or filter to match items whose specified property value is less than or equal to the specified value.

The le() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is less than or equal to the specified value.

It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

If a property contains a number as a String, that value will be compared alphabetically and not numerically. Items that do not have a value for the specified property are ranked lowest.

The following types of properties can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so "ABC" is less than or equal to "abc" (because of the less than), but "abc" is not less than or equal to "ABC".
  • Reference: Compares by the ID of the referenced item as a String.
Method Declaration
Copy
function le(propertyName: string, value: union): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with value.


valueunionRequired

The value to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.le("age", 25);
Did this help?

lt( )


Refines a query or filter to match items whose specified property value is less than the specified value.

The lt() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is less than the specified value.

It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

If a property contains a number as a String, that value will be compared alphabetically and not numerically. Items that do not have a value for the specified property are ranked lowest.

The following types of properties can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so "Text" is less than "text".
  • Reference: Compares by the ID of the referenced item as a String.
Method Declaration
Copy
function lt(propertyName: string, value: union): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with value.


valueunionRequired

The value to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.lt("age", 25);
Did this help?

ne( )


Refines a query or filter to match items whose specified property value does not equal the specified value.

The ne() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property does not equal the specified value.

It only matches values of the same type. For example, a number value stored as a String type is considered not equal to the same number stored as a Number type.

Matching strings with ne() is case sensitive, so "text" is not equal to "Text".

If the value of the propertyName property is an Array, ne() includes items in which none of the elements of the Array match the specified value.

Method Declaration
Copy
function ne(propertyName: string, value: any): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with value.


valueanyRequired

The value to match against.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.ne("status", "active");
Did this help?

not( )


Adds a not condition to the query or filter.

The not() function adds a not condition to a WixDataQuery or WixDataFilter. A query or filter with a not returns all the items that match the query or filter as defined up to the not function, but don't match the query or filter passed to the not function.

If the query or filter only contains a not() function, it returns all the items that don't match the query defined by the not method.

The collections referenced by both the initial query and the query passed to the not function must be the same.

Method Declaration
Copy
function not(query: WixDataQuery): WixDataQuery;
Method Parameters
queryWixDataQueryRequired

A query to add to the initial query as a not condition.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query1.not(query2);
Did this help?

or( )


Adds an or condition to the query or filter.

The or() function adds an inclusive or condition to a WixDataQuery or WixDataFilter. A query or filter with an or returns all the items that match the query or filter as defined up to the or function, the items that match the query or filter passed to the or function, and the items that match both.

The collections used by both the initial query and the query passed to the or function must be the same.

The 'or()' function is designed to work with 2 or more queries or filters. If you use it on its own, it will return all the items in a collection.

Method Declaration
Copy
function or(query: WixDataQuery): WixDataQuery;
Method Parameters
queryWixDataQueryRequired

A query to add to the initial query as an or condition.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query1.or(query2);
Did this help?

startsWith( )


Refines a query or filter to match items whose specified property value starts with a specified string.

The startsWith() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property starts with the defined string. Matching with startsWith() is not case sensitive, so "TEXT" starts with "tex".

You can only use startsWith() with a property whose value is a String or Reference. When using a Reference, startsWith() matches by the ID of the referenced item as Strings.

Method Declaration
Copy
function startsWith(propertyName: string, string: string): WixDataQuery;
Method Parameters
propertyNamestringRequired

The property whose value will be compared with the string.


stringstringRequired

The string to look for at the beginning of the specified property value.

Returns
Return Type:WixDataQuery
JavaScript
let newQuery = query.startsWith("last_name", "M");
Did this help?