Setting Up a Dataset
Adding a Collection
A collection is a table inside of a database that stores your site’s data/information. To create a collection, turn on Dev Mode from your site’s top bar, and the Content Manager button will appear. Click on the Content Manager button. Depending on the template you used to create your site, you may already have a preset collection or two created for you. In the image below, we have a “Coupons” collection. Ignore that for now, and click Create New Collection to start with a blank slate.
To get started, create a collection called ‘Desserts’, because everyone has a sweet tooth! You can keep the default ID, and set the permissions to Site Content. Next, click Create Collection, and add fields for a Title, Image, and Main Ingredient. Finally, fill in the desserts you want to store.
To get the data from your collection to show up on your page, you need a dataset! Datasets are like imaginary wires between your collection and page. Through these wires, you control how visitors interact with the data in your collections.
Collections carry their own permissions that allow different user roles to interact with the collection, based on their role. You set these permissions during the creation of the collection, and they can be changed at any time by clicking Edit Settings on the collection.
The default permissions of a collection are set to “Site Content”. This means anyone can read from the collection, but only an admin can create, update, and delete content. During development, creating, updating, and deleting from the collections won’t be an issue in Preview. This is because your user role is set to admin by default. And since admins have all permissions, they are able to read, write, create, and delete.
But you may run into a permissions issue when you publish. Since you (or anyone using the site) are not an admin on the published site, creating, updating, and deleting content won’t work. This is by design, since most of the time you wouldn’t want anyone visiting the site to be able to manipulate a live collection. The solution here is to go into the collection settings and set the permissions to Custom Use. From there, set all of the permissions to Anyone, or dial down the individual roles to choose exactly who you want to be able to read, write, update, and delete.
Be sure to look over Wix’s article about collection permissions to go into more detail about permissions, user roles, and presets.
Adding a Dataset
To add a dataset:
- Click on the Content Manager Button.
- Click the Add Content Elements tab.
- Click Dataset.
You’ll now see a new dataset icon on the page. This icon will not be visible on the published site, so you can move it around wherever you’d like. You can test this out by clicking the Preview button.
Setting up a Dataset
The dataset is currently unconfigured because you haven’t connected it to any data yet. Click on the icon, and then click Settings. Here you can:
Connect the Dataset to a Content Collection
Choose which collection you want the dataset to connect to. You’ll connect to the Desserts collection you created earlier.
Give it a Name
This will default to the name of the collection followed by “dataset”, e.g. “Desserts dataset”. The default name is perfect for most cases, but if you have multiple datasets connecting the same collection, you may want to choose a more unique name that describes the particular dataset better.
Set the Mode
Read-only: Visitors cannot edit, add to, or delete any content in your collection. Think of it like a book. You want users to be able to read it but you don’t want them to add or edit the book’s pages.
Write-only: Data from your collection is not displayed on the page, but visitors can add data to the collection through a web form. Think of it like an election. You can cast your vote, but you can’t edit, or check how others voted.
Read & Write: Data from your collection is displayed on the page, where visitors can add to, and/or edit it. Think of it like a shared grocery list. You, and anyone who has access to it, can read it, as well as edit the items on it.
Set Number of Items to Display
This is the number of items that will initially be displayed when the page loads. The default number of 12 is a good place to start. You can always limit, or expand it, based on how many results you’d like to display at a time.
Filter and Sort the data
You can filter and sort the dataset to control which items appear on the page, and in what order. Let’s say you’re craving chocolate and no other dessert will do. You can set a filter to meet your criteria, like setting the filter to only display desserts that contain chocolate. Then using the sort option, you can list the results as you prefer — for example, you can sort the desserts in alphabetical order.
After connecting, naming, and customizing the dataset, the icon is now connected to your Desserts collection. Great job! You’ve taken the first step in utilizing data on your website. Just like prepping ingredients for baking, it’s important to set up your database components prior to using the data. The next step is to connect your dataset to an element!