---
title: Custom widgets
project: Dashboard
version: 1.0
section: development
language: sk
translation: missing
license: Total.js Enterprise
url: https://totaljs.es/docs/sk/dashboard/1-0/development/custom-widgets/
updated: 2026-11-20T06:40:27.732Z
---

# Custom widgets

> Add your own widget to Dashboard with one HTML file in the folder dashboard.

Every widget of Dashboard is one HTML file in the folder `dashboard` of the app. Add your own file there and it appears in the **Widgets** window like the built-in ones. The file name without `.html` is the ID of the widget.

With `autowidgetwatcher : true` in the `config` file, Dashboard picks up new, changed and removed files within a few seconds. Without it, restart Dashboard. See [Configuration](../../reference/configuration/).

## The parts of the file

A widget file has three parts:

| Part | Runs in | What it holds |
|---|---|---|
| `<script total>` | the server | The name, icon and default settings of the widget, and optional [data sources](../data-sources/). |
| `<settings>` | the browser | The HTML of the settings form of the widget. |
| `<body>` | the browser | The `<style>` and the `<script>` that draw the widget. |

## A first widget

This widget, saved as `dashboard/total.html`, adds up the values of one report and shows the sum:

```html
<script total>
	exports.name = 'Total';
	exports.icon = 'ti ti-calculator';
	exports.color = '#34A853';
	exports.config = { dataset: [], interval: 0 };
</script>

<settings>
	<div class="padding">
		<ui-component name="dataset" path="?.dataset" config="type:chart;limit:1" class="m">Dataset</ui-component>
		<ui-component name="input" path="?.interval" config="type:number">Refresh interval</ui-component>
	</div>
</settings>

<body>
	<style>
		.CLASS .total { height: 100%; display: flex; align-items: center; justify-content: center; font-weight: bold; }
	</style>
	<script>
		exports.offset = { lg: { width: 3, height: 2 }, md: { width: 4, height: 3 }, xs: { width: 6, height: 3 } };
		exports.actions = { move: true, remove: true, resize: true, resizeX: true, resizeY: true, settings: true };
		exports.header = true;

		exports.make = function(instance, config, element) {

			instance.refresh = function() {
				var item = config.dataset[0];
				if (!item) {
					element.html('<div class="total">-</div>');
					return;
				}
				instance.dataset(item, function(response) {
					var sum = 0;
					for (var serie of response || [])
						for (var point of serie.data)
							sum += point.y;
					element.html('<div class="total">' + sum + '</div>');
				});
			};

			instance.service = function(counter) {
				if (config.interval && counter % config.interval === 0)
					instance.refresh();
			};

			instance.configure = instance.refresh;
			instance.refresh();
		};
	</script>
</body>
```

Drag **Total** onto a dashboard, select its gear icon and choose a report in **Dataset**.

## The settings form

Each element in `<settings>` with a `path` that starts with `?.` edits the key of the same name in the settings of the widget. `exports.config` gives the values of a new widget.

- `<ui-component name="dataset" path="?.dataset" config="type:chart;limit:1">` is the **Dataset** picker. `limit` is the largest number of reports.
- `<ui-component name="input" path="?.interval" config="type:number">` is a number box. Use `type:checkbox` for a check box.

## Styles

In `<style>`, write `.CLASS` in front of every selector. Dashboard replaces it with a class of the widget, so your styles do not change other widgets.

Every key is described in [Widget reference](../widget-api/).
