About Filtering and Sorting Collection Content Displayed in Page Elements

When a dataset connector is connected to a collection, it has access to all of that collection's fields and items. Hiding a field in the Content Manager does not hide the field from the dataset connector. Similarly, sorting or filtering items in the Content Manager does not sort or filter the items in your connector. This means that if you want to determine which items appear on your page and in what order, you need to control this from the connector on the current page.

You filter and sort dataset connectors from their Dataset Settings panel. 
Notes:
  • Filtering and sorting a dataset only affects the dataset, not the collection. 
  • Datasets with "Write-only" modes cannot sort or filter, only "Read-only" or "Read-Write" modes can sort or filter. 

Filtering Your Dataset Connector

When you filter your dataset, you define three things:
  1. The field you want to filter by.
  2. The condition you want to use when checking whether items meet the filter criteria.
  3. The value you want the filter to match. 

Let's look at an example. Say you have a site that lists your favorite recipes, and you have categorized them by cuisine. Now you want to filter your dataset connector to only show your Tex Mex recipes. The field would be "Cuisine," the condition would be "Is," and the value would be "Tex Mex." The image below shows how this would look.
Note:
In the Dataset Settings panel, click + Add Filter to open the Add Filter panel.

Field

Click the dropdown and then select the field in your collection you want to filter by. Note that you can only filter by text, number, boolean, reference, and owner fields. 

Condition

Click the dropdown and then select the filter condition for this field. The available filter conditions vary depending on the type of field you are filtering by. 
  • Text fields have conditions like "Is" or "Starts with." 
  • Number fields have conditions like "Greater than" or "Equals." 
  • Boolean fields can be either "True" or "'False."

You can only filter by a reference field if your page has a dataset that is connected to the referenced collection. Reference fields only have one condition, "Same as."

When filtering by the Owner field, you can choose between "Is" and "Is not" the currently logged-in user. 
Note:
You can also filter one dataset by a second dataset so you can display related information from more than one collection on the same page, even though the collections themselves are not connected with reference fields. See here for instructions.

Value

This is the value that you want to use for the filter condition you defined. 
  • In the case of reference fields, choose the referenced collection.
  • In the case of the "Owner" field, the "logged-in user" value is automatically filled in.

Changing or Removing a Filter

Once you have defined a filter, its description is listed in the Dataset Settings panel.



  • To change the filter, select it, click the ellipsis, and then click Edit.
  • To remove the filter, select it, click the ellipsis, and then click Delete.

Filtering by Multiple Fields

You can add more than one filter. For example, you might want to filter your recipes collection by the Tex Mex cuisine and also by whether they are gluten-free. 

When you define more than one filter, both filter conditions work together. This means that in order to be displayed, items must match both filter conditions. If no items in your collection meet both filter conditions, nothing will be displayed. 

Filtering Dynamic Pages

It is important to remember that dynamic pages are already filtered by their URL. This means that adding a filter condition to a dynamic page creates two filter conditions for that page.

In the case of a dynamic item page, the page will only be displayed if the item in question matches both the URL condition and the new filter condition. If someone tries to go to the page using its URL, they will get a 404 page. In the case of a dynamic list page, the page will only include items that meet both the URL condition and the new filter condition.

You can use this to your advantage to control which item pages can be displayed without needing to modify the URL. For example, you could add a field to your collection called "Active," and then add a filter condition based on that field so that only active items are displayed.

Sorting Your Dataset Connector

Sorting your dataset connector controls the order in which items are displayed in repeaters, tables, and galleries. If you have back and next buttons attached to your dataset, the sort controls the order in which the items appear when visitors use the buttons to navigate.

When you sort your dataset, you define two things:
  1. The field you want to sort by.
  2. The order in which you want the items to appear. 

The default sort order is the date the item was added, with newer items appearing first. This date appears in the "Date_Created" system field. When you add a new sort, the default sort disappears.

If we continue our example from above, we want the recipes to be listed alphabetically by recipe name. So our field would be "Recipe," and our order would be "A-Z."  The image below shows how this looks.
Note:
In the Dataset Settings panel, click + Add Sort to open the Add Sort panel.

Field

Click Choose to open the dropdown and select the field in your collection you want to use to sort your dataset. You can only sort by text, number, boolean, and date fields.

Order

Click the dropdown to select the sort order. The options vary depending on the type of field you selected. For example, number field can be sorted smallest to largest or largest to smallest. Boolean fields can be sorted as "True first" or "False first."

Changing or Removing a Sort

Once you have defined a sort, its description is listed in the Dataset Settings panel.

  • To change the sort, select it, click Show More, and then click Edit.
  • To remove the sort, select it, click Show More, and then click Delete.

Sorting by Multiple Fields

You can sort by more than one field, if you want. When you do, the items are sorted by the first sort condition and then by the second sort condition, and so on. 

This is relevant if you have more than one item that matches your first sort condition. For example, if you sort your recipes by cuisine, you might want to add a second sort by recipe name so that under each cuisine, the recipes appear in alphabetical order.

You might even want to consider adding a field to your collection specifically to use for sorting the items in your dataset connector. This could be a number field, for example, or some other field.

Did this help?

|
Hire a Wix Partner
Get help with your website's design, marketing and small tasks from a professional freelancer or agency.
Start Now