---
title: Data sources
project: Dashboard
version: 1.0
section: development
language: en
license: Total.js Enterprise
url: https://totaljs.es/docs/dashboard/1-0/development/data-sources/
updated: 2026-11-20T06:52:02.970Z
---

# Data sources

> Give widgets data from your own code with dashboard.source() on the server.

Reports with chart data are one data source. A widget file can register more in `exports.install`. Their entries then appear in the **Dataset** picker next to the reports, and `instance.dataset()` loads their data.

## An example

This file, saved as `dashboard/visits.html`, adds the entry **Demo visits** with three fixed points:

```html
<script total>
	exports.name = 'Visits source';
	exports.hidden = true;

	var ITEM = { id: 'visits', name: 'Demo visits', icon: 'ti ti-users', color: '#FBBC05' };

	exports.install = function(dashboard) {
		dashboard.source('visits', {
			search: function(model, next) {
				next(model.type === 'chart' ? [ITEM] : []);
			},
			detail: function(model, next) {
				next(model.id === 'visits' ? ITEM : null);
			},
			action: function(model, next) {
				next([{ id: 'visits', name: 'Demo visits', format: '{0}', decimals: 0, data: [{ x: 'Mon', y: 120 }, { x: 'Tue', y: 150 }, { x: 'Wed', y: 90 }] }]);
			}
		});
	};

	exports.uninstall = function(dashboard) {
		dashboard.source('visits', null);
	};
</script>
```

The built-in widgets ask for the type `chart`, so return your entries for that type.

## API

### dashboard.source(name, options)

Type: `method`

Registers a data source, or removes it when options is null.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the source. |
| `options` | `Object` | yes |  | The functions `search`, `detail` and `action`, or `null` to remove the source. |

Call it in `exports.install` of a widget file. The name must be unique and must not contain `~`.

### search: function(model, next) {}

Type: `event`

Returns the entries that the Dataset picker offers.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model.search` | `String` | no |  | The text typed in the picker. It can be empty. |
| `model.type` | `String` | yes |  | The type the widget asks for, for example `chart`. |
| `model.user` | `Object` | yes |  | The signed-in user. Return only the entries this user may see. |
| `next` | `Function` | yes |  | `next(list)` returns the entries. |

Return a list of objects with `id`, `name`, `icon` and `color`.

### detail: function(model, next) {}

Type: `event`

Returns the name, icon and colour of one entry.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model.id` | `String` | yes |  | The id of the entry. |
| `model.type` | `String` | yes |  | The type the widget asks for. |
| `model.user` | `Object` | yes |  | The signed-in user. |
| `next` | `Function` | yes |  | `next(object)` returns the entry. |

Dashboard calls it when the settings of a widget open. Return `null` for an entry that no longer exists; it is taken off the Dataset.

### action: function(model, next) {}

Type: `event`

Returns the data of one entry.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model.id` | `String` | yes |  | The id of the entry. |
| `model.type` | `String` | yes |  | The type the widget asks for. |
| `model.user` | `Object` | yes |  | The signed-in user. |
| `model.query` | `Object` | yes |  | The query arguments of the request. |
| `next` | `Function` | yes |  | `next(data)` returns the data. |

For the type `chart`, return a list of series. Each series has `id`, `name`, `icon`, `color`, `format`, `decimals` and `data`, a list of points with `x` and `y`.
