# Custom Elements with dataset

**URL:** <https://forum.wixstudio.com/t/custom-elements-with-dataset/27051>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [November 17, 2020, 10:50am UTC](https://forum.wixstudio.com/t/custom-elements-with-dataset/27051 "2020-11-17T10:50:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bakieness](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bakieness/32/8068_2.png) [@bakieness](https://forum.wixstudio.com/u/bakieness)\
**Post date:** [November 17, 2020, 10:50am UTC](https://forum.wixstudio.com/t/custom-elements-with-dataset/27051/1 "2020-11-17T10:50:18Z")

</div>

Is there a way of using a dataset query inside of a custom element. On the support page (https://support.wix.com/en/article/custom-element-faqs) its says the following:

‘Can I Connect Custom Elements to Data in a Collection?  
Yes, you can connect custom elements to collections using Corvid’s [Data](https://www.wix.com/corvid/reference/wix-data.html) and [Dataset](https://www.wix.com/corvid/reference/wix-dataset.html) APIs.’

But I don’t know how to do it. I have have tried importing wixData from wix-data at the top of my custom element however this stops my custom element from displaying.

I need to create checkboxes based on the number of items in a dataset. I have been able to create the checkboxes based on a static array in the custom element but want to do it based on the dataset so I don’t have to manually keep changing the array in the custom element.

Below is what I need in my custom element.

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

wixData.query('testdata')
        .limit(1000)
        .find()
        .then(results => {
            console.log(results.items)
        });

```

Or if it is possible to send in an array from my page file to the custom element that would work.

---

<div class="post-metadata">

**Author:** ![iSamurai](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/isamurai/32/89043_2.png) [@iSamurai](https://forum.wixstudio.com/u/iSamurai)\
**Post date:** [April 4, 2024, 3:37pm UTC](https://forum.wixstudio.com/t/custom-elements-with-dataset/27051/2 "2024-04-04T15:37:57Z")

</div>

You can send data from your Page code to Custom Element through **attributes**.

1. In your Custom Element _observedAttributes()_ observe an attribute for change.
2. Use _attributeChangedCallback()_ to treat the changes in the attribute. Use its new value in your Custom Element logic.
3. In the Page code use _$w(‘#customElement’).setAttribute( ‘attribute-name’, value )_  
\*) Note that the value of an attribute must be a _String_ so use _JSON.stringify()_ and _JSON.parse()_

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [April 4, 2024, 9:38pm UTC](https://forum.wixstudio.com/t/custom-elements-with-dataset/27051/3 "2024-04-04T21:38:00Z")

</div>

> [@bakieness](#):
>
> ‘Can I Connect Custom Elements to Data in a Collection?

If you are not familiar with CUSTOM-ELEMENT → use a HTML-Component for your purposes.
