|
| 1 | +--- |
| 2 | +title: Filtering & Sorting |
| 3 | +--- |
| 4 | + |
| 5 | +import { Callout } from 'nextra/components' |
| 6 | + |
| 7 | +# Filtering & Sorting |
| 8 | + |
| 9 | +You can filter and sort collection items on your pages to build directories, listings, blogs, marketplaces, and other data-driven experiences. Filters reduce the dataset before items render, and sorting controls the display order. |
| 10 | + |
| 11 | +## Adding Filters to a Collection List |
| 12 | + |
| 13 | +Filters are configured on collection layers (Collection List elements). Each filter targets a collection field and applies a condition to include or exclude items. |
| 14 | + |
| 15 | +1. Select a **Collection List** layer on the canvas |
| 16 | +2. In the right panel, open the **Filters** section |
| 17 | +3. Click **+** to add a filter condition |
| 18 | +4. Choose a collection field to filter by |
| 19 | +5. Select an operator and enter a value |
| 20 | + |
| 21 | +Filtered items update immediately in the editor preview. |
| 22 | + |
| 23 | +## Filter Operators |
| 24 | + |
| 25 | +Available operators depend on the field type: |
| 26 | + |
| 27 | +### Text Fields |
| 28 | + |
| 29 | +Text, rich text, email, phone, and color fields support: |
| 30 | + |
| 31 | +| Operator | Description | |
| 32 | +|----------|-------------| |
| 33 | +| **is** | Exact match | |
| 34 | +| **is not** | Does not match | |
| 35 | +| **contains** | Value includes the text | |
| 36 | +| **does not contain** | Value does not include the text | |
| 37 | +| **is present** | Field has a value | |
| 38 | +| **is empty** | Field has no value | |
| 39 | + |
| 40 | +### Number Fields |
| 41 | + |
| 42 | +| Operator | Description | |
| 43 | +|----------|-------------| |
| 44 | +| **is** | Equals the number | |
| 45 | +| **is not** | Does not equal the number | |
| 46 | +| **less than** | Value is below the number | |
| 47 | +| **less than or equal** | Value is at or below the number | |
| 48 | +| **greater than** | Value is above the number | |
| 49 | +| **greater than or equal** | Value is at or above the number | |
| 50 | + |
| 51 | +### Date Fields |
| 52 | + |
| 53 | +| Operator | Description | |
| 54 | +|----------|-------------| |
| 55 | +| **is** | Matches the date | |
| 56 | +| **is before** | Earlier than the date | |
| 57 | +| **is after** | Later than the date | |
| 58 | +| **is between** | Falls within a date range (requires two values) | |
| 59 | +| **is empty** | No date set | |
| 60 | +| **is not empty** | Has a date | |
| 61 | + |
| 62 | +### Boolean Fields |
| 63 | + |
| 64 | +| Operator | Description | |
| 65 | +|----------|-------------| |
| 66 | +| **is** | True or false | |
| 67 | + |
| 68 | +### Reference Fields |
| 69 | + |
| 70 | +Reference and single-asset fields support: |
| 71 | + |
| 72 | +| Operator | Description | |
| 73 | +|----------|-------------| |
| 74 | +| **is one of** | Matches any of the selected items | |
| 75 | +| **is not one of** | Does not match any of the selected items | |
| 76 | +| **exists** | Has a linked item | |
| 77 | +| **does not exist** | No linked item | |
| 78 | + |
| 79 | +When you use **is one of** or **is not one of**, a multi-select dropdown loads items from the referenced collection so you can pick values directly. |
| 80 | + |
| 81 | +### Multi-Reference Fields |
| 82 | + |
| 83 | +| Operator | Description | |
| 84 | +|----------|-------------| |
| 85 | +| **is one of** | Contains at least one of the selected items | |
| 86 | +| **is not one of** | Contains none of the selected items | |
| 87 | +| **contains all of** | Contains every selected item | |
| 88 | +| **contains exactly** | Contains only the selected items, no more | |
| 89 | +| **item count** | Number of linked items matches a comparison (equals, less than, greater than, etc.) | |
| 90 | +| **has items** | At least one linked item | |
| 91 | +| **has no items** | No linked items | |
| 92 | + |
| 93 | +## Filter Logic |
| 94 | + |
| 95 | +Filters use a group-based logic system: |
| 96 | + |
| 97 | +- **Conditions within a group** use **OR** logic — an item passes if it matches any condition in the group |
| 98 | +- **Groups** use **AND** logic — an item must pass all groups to appear |
| 99 | + |
| 100 | +This lets you build expressive filters. For example, to show products that are "Electronics" or "Books" AND cost less than $50, create two groups: one with category conditions (OR) and one with a price condition. |
| 101 | + |
| 102 | +### Adding Multiple Conditions |
| 103 | + |
| 104 | +To add an **OR** condition within a group, click the **+** button next to "Or" inside the group. |
| 105 | + |
| 106 | +To add an **AND** group, click the **+** button at the top of the Filters panel. |
| 107 | + |
| 108 | +## Sorting |
| 109 | + |
| 110 | +Control the display order of collection items using the sort settings on the collection layer: |
| 111 | + |
| 112 | +| Sort Option | Description | |
| 113 | +|-------------|-------------| |
| 114 | +| **None** | Default database order | |
| 115 | +| **Manual** | Custom order set by drag-and-drop reordering in the CMS | |
| 116 | +| **Random** | Randomized order on each page load | |
| 117 | +| **Field** | Sort by any collection field in ascending or descending order | |
| 118 | + |
| 119 | +When sorting by a field, you choose the field and the direction (ascending or descending). Common sort fields include date (newest first), name (alphabetical), or price (low to high). |
| 120 | + |
| 121 | +## Pagination |
| 122 | + |
| 123 | +When a collection has many items, enable pagination to split them across pages: |
| 124 | + |
| 125 | +1. Select a Collection List layer |
| 126 | +2. In the right panel, find **Pagination** |
| 127 | +3. Enable pagination and choose a mode: |
| 128 | + |
| 129 | +| Mode | Description | |
| 130 | +|------|-------------| |
| 131 | +| **Pages** | Traditional page navigation with previous/next buttons and page info | |
| 132 | +| **Load More** | A button that appends the next batch of items | |
| 133 | + |
| 134 | +Set the **items per page** count to control how many items appear at once. Pagination works with filters — only items that pass the filters are counted and paginated. |
| 135 | + |
| 136 | +### Styling Pagination Controls |
| 137 | + |
| 138 | +When pagination is enabled, Ycode generates pagination controls (previous/next buttons, page info text). You can style these controls through the pagination layer settings in the design panel. |
| 139 | + |
| 140 | +<Callout type="info" title="Tip"> |
| 141 | +Combine filters, sorting, and pagination to build complete listing experiences. For example, a product directory with category filters, price sorting, and 12 items per page. |
| 142 | +</Callout> |
0 commit comments