> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: setFilter(filter: object)

# Method package: w

# Method menu location: w --> Dataset --> setFilter

# Method Link: https://dev.wix.com/docs/velo/velo-only-apis/$w/dataset/set-filter.md

# Method Description:

Sets the dataset filter.

`setFilter()` filters out items that don't match the filter
 criteria.

 A filter object is created by calling [`filter()`](https://dev.wix.com/docs/velo/apis/wix-data/filter.md)
 on `wixData` and chaining one or more of the following Wix Data
 filter functions.

 + [and](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/and.md): See note below.
 + [between](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/between.md)
 + [contains](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/contains.md)
 + [endsWith](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/ends-with.md)
 + [eq](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/eq.md)
 + [ge](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/ge.md)
 + [gt](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/gt.md)
 + [hasAll](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/has-all.md)
 + [hasSome](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/has-some.md)
 + [isEmpty](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/is-empty.md)
 + [isNotEmpty](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/is-not-empty.md)
 + [le](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/le.md)
 + [lt](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/lt.md)
 + [ne](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/ne.md)
 + [not](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/not.md): See note below.
 + [or](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/or.md): See note below.
 + [startsWith](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/starts-with.md)


 Setting a dataset's filter overrides existing filters that were previously
 set using `setFilter()` or using the Dataset Settings
 panel in the editor.

 To clear a dataset's current filter, call `setFilter()` and pass it an
 empty filter. You create an empty filter by calling the [`filter()`](https://dev.wix.com/docs/velo/api-reference/wix-data/filter.md)
 function without chaining any of the additional filter functions mentioned above.

 Calling `setFilter()` on a write-only dataset causes an error.

 You will need to import `wix-data` in order to create a `WixDataFilter` object.
 > **Notes:**
 > + When using the [and](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/and.md), [not](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/not.md), or [or](https://dev.wix.com/docs/velo/api-reference/$w/wix-data-filter/or.md) functions, be sure to pass them a `WixDataFilter` object created by calling the [`filter()`](https://dev.wix.com/docs/velo/api-reference/wix-data/filter.md) function and not a `WixDataQuery` object created by calling the [`query()`](https://dev.wix.com/docs/velo/api-reference/wix-data/query.md) function.
 > + When using a read-write dataset and linked input elements, calling any of the following functions will save any changes made in the linked input elements.
>    + [setFilter()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/set-filter.md)
>    + [setSort()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/set-sort.md)
>    + [nextPage()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/next-page.md)
>    + [previousPage()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/previous-page.md)
>    + [loadPage()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/load-page.md)
>    + [setPageSize()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/set-page-size.md)
>    + [setCurrentItemIndex()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/set-current-item-index.md)
>    + [next()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/next.md)
>    + [previous()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/previous.md)
>    + [save()](https://dev.wix.com/docs/velo/api-reference/$w/dataset/save.md)



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Set a dataset's filter

```javascript
import wixData from 'wix-data';

// ...

$w("#myDataset").setFilter( wixData.filter()
  .startsWith("lastName", "D")
  .ge("age", "21")
);

```

## Build and set a dataset's filter

```javascript
import wixData from 'wix-data';

// ...

function filter(low, high) {
  let filter = wixData.filter();

  if(low) {
    filter = filter.ge("price", low);
  }

  if(high) {
    filter = filter.le("length", high);
  }

  $w("#myDataset").setFilter(filter);
}

```

## Set a dataset's filter

```javascript
import wixData from 'wix-data';

// ...

$w("#myDataset").setFilter( wixData.filter()
  .startsWith("lastName", "D")
  .ge("age", "21")
)
.then( () => {
  console.log("Dataset is now filtered");
} )
.catch( (err) => {
  console.log(err);
} );
```

## Clear a dataset's filters

```javascript
import wixData from 'wix-data';

// ...

$w("#myDataset").setFilter( wixData.filter() );
```

## Set a dataset's filter with an or condition

```javascript
import wixData from 'wix-data';

// ...

$w("#myDataset").setFilter( wixData.filter()
  .startsWith("lastName", "D")
  .or(
    wixData.filter()
      .ge("age", "21")
  )
)
.then( () => {
  console.log("Dataset is now filtered");
} )
.catch( (err) => {
  console.log(err);
} );
```

---