# DataSource

## Live examples

{% hint style="success" %}
[In-Memory DataSource](https://demos.dikesoft.com/dk-grid/datasource/in-memory) live example.
{% endhint %}

{% hint style="success" %}
[Custom DataSource](https://demos.dikesoft.com/dk-grid/datasource/custom) live example.
{% endhint %}

## Specifying data

Every DikeGrid instance accepts data from an <mark style="color:green;">`Array`</mark>, <mark style="color:green;">`Observable< Array>`</mark>, a <mark style="color:green;">`DikeGridDataSource`</mark>, or simply a <mark style="color:green;">`DataSource`</mark>.

{% hint style="info" %}
Remember, the <mark style="color:green;">`DataSource`</mark> definition is an <mark style="color:blue;">`abstract`</mark> class with two methods: `connect()` and `disconnect()`. Therefore, you can provide an instance of a class that derives from the <mark style="color:green;">`DataSource`</mark> class.
{% endhint %}

Depending on the data you provide, there are two types of DataSource: an **In-Memory** DataSource and a **Custom** DataSource.

## Wrapping data entries

It does not matter how you provide your data set. The DikeGrid will **wrap** every data entry in a <mark style="color:green;">`DikeGridDataRowEntry`</mark> instance.

The <mark style="color:green;">`DikeGridDataRowEntry`</mark> wrapper helps to know several features during execution, for instance, when the user modifies a data row or when it is selected, the row status, among others.

{% hint style="success" %}
For further details, see the [<mark style="color:green;">`DikeGridDataRowEntry`</mark>](https://docs.dikesoft.com/reference/classes/rows#dikegriddatarowentry-less-than-t-greater-than) definition.
{% endhint %}

Once the DikeGrid **receives** and **wraps** the data, it assigns and emits a **unique id**. You can get this id by listening to the `dataDeliveryIdChange` event.

{% hint style="info" %}
Indeed, a **DikeGrid** instance will send a **unique id** every time you provide a new set of entries. It means that you can have an **Observable** or a <mark style="color:green;">`DikeGridDataSource`</mark>, and if you change the entries set, the DikeGrid will wrap these new entries.
{% endhint %}

Let us listen to the `dataDeliveryIdChange` event:

{% tabs %}
{% tab title="in-memory-data-source.component.html" %}

```markup
<dike-grid id="grid-in-memory-datasource" height="650px" #grid="dkgGrid"
    (dataDeliveryIdChange)="onDataDeliveryIdChange($event)">
</dike-grid>
```

{% endtab %}

{% tab title="in-memory-data-source.component.ts" %}

```typescript
onDataDeliveryIdChange(id: string): void {
  console.log(`Data delivery id: ${id}`);
}
```

{% endtab %}
{% endtabs %}

Open your **dev console** to see the emitted id.

{% hint style="info" %}
The DikeGrid internally creates a <mark style="color:green;">`DikeGridDataSource`</mark> instance to wrap every data entry.
{% endhint %}

{% hint style="warning" %}
Be aware that every time a DikeGrid instance wraps the provided entries, it **resets** the **edition** and **selection** operations. It means that the DikeGrid removes the history of changes and deselects rows.
{% endhint %}

### Row Ids

The DikeGrid sets a **unique id** number for every **row** during the wrapping operation. This id number is a consecutive number starting at the **zero number**.

You can open any live example, go to the [Floating Configuration Panel](https://docs.dikesoft.com/overview#floating-configuration-panel), scroll to the **Rows** section and mark the **Row Id** checkbox.

![Floating Configuration Panel - Rows](https://3888584995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpDxfe6pgRLqBLMQgZ0kG%2Fuploads%2FvZFuFLhgPkpXsleW5J9q%2Fgrid-structure-type-content-row-height.png?alt=media\&token=861d95e7-df97-45d2-866e-8133179d441a)

![Row Ids](https://3888584995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpDxfe6pgRLqBLMQgZ0kG%2Fuploads%2FZuvnTVUV0aeSn0lNU7nT%2Fin-memory-datasource-row-id.png?alt=media\&token=efaaddcb-42c0-4c0f-b4cd-bbe5240a9e5f)

### Timestamp / Row status

Other values that the DikeGrid creates and assigns to every row are the **timestamp** and the initial **row status**.

The timestamp corresponds to the row **creation** time and the row status to the <mark style="color:red;">`Read`</mark> value. The <mark style="color:red;">`Read`</mark> value means that the user has not modified the row.

{% hint style="info" %}
The DikeGrid uses the row status and the timestamp properties to manage the edition operations. See the [Row Edition](https://docs.dikesoft.com/editing/row-edition) section.
{% endhint %}
