Widget reference
The keys and functions of a widget file, in the server part and in the browser part.
Diese Seite ist noch nicht übersetzt. Du liest das Original.
Auf dieser Seite
A widget file sets keys on exports in two places: in <script total> on the server, and in the <script> of <body> in the browser. See Custom widgets for a whole file.
Entries of type property are keys you set. Entries of type event are functions you define and Dashboard calls. Entries of type method are functions that Dashboard gives you.
API
property
exports.name = 'Total';
The name of the widget in the Widgets window and the first title of a new widget.
exports.name = 'Total';Set it in <script total>.
property
exports.icon = 'ti ti-calculator';
The icon of the widget in the Widgets window.
exports.icon = 'ti ti-calculator';A Total.js icon class. Set it in <script total>.
property
exports.color = '#34A853';
The colour of the icon in the Widgets window.
exports.color = '#34A853';Set it in <script total>.
property
exports.config = { dataset: [], interval: 0 };
The settings of a new widget.
exports.config = { dataset: [], interval: 0 };Set it in <script total>. The settings form edits these keys, and exports.make receives them as config.
event
exports.install = function(dashboard) {}
Runs on the server when the widget is loaded.
exports.install = function(dashboard) {}| Parameter | Typ | Beschreibung |
|---|---|---|
dashboard |
Object |
The dashboard on the server. See Data sources. |
Register data sources here with dashboard.source().
event
exports.uninstall = function(dashboard) {}
Runs on the server before the widget is replaced or removed.
exports.uninstall = function(dashboard) {}| Parameter | Typ | Beschreibung |
|---|---|---|
dashboard |
Object |
The dashboard on the server. |
Remove here what exports.install registered, for example with dashboard.source(name, null).
property
exports.offset = { lg: { width: 3, height: 2 }, md: { width: 4, height: 3 }, xs: { width: 6, height: 3 } };
The size of a new widget on the grid, for large, medium and extra small screens.
exports.offset = { lg: { width: 3, height: 2 }, md: { width: 4, height: 3 }, xs: { width: 6, height: 3 } };Width and height are in cells of the grid. The grid is 12 cells wide. Set it in the browser part.
property
exports.actions = { move: true, remove: true, resize: true, resizeX: true, resizeY: true, settings: true };
What people may do with the widget on the dashboard.
exports.actions = { move: true, remove: true, resize: true, resizeX: true, resizeY: true, settings: true };move lets them drag it, resize, resizeX and resizeY let them resize it, remove shows the bin icon and settings shows the gear icon. Set it in the browser part.
property
exports.header = true;
Shows the title bar of the widget.
exports.header = true;Set it in the browser part.
property
exports.import = ['https://cdnjs.cloudflare.com/ajax/libs/apexcharts/3.54.1/apexcharts.min.js'];
Scripts and style sheets that the widget needs.
exports.import = ['https://cdnjs.cloudflare.com/ajax/libs/apexcharts/3.54.1/apexcharts.min.js'];Dashboard loads each address once, before it draws the dashboard. Set it in the browser part.
event
exports.make = function(instance, config, element) {}
Draws one widget on the dashboard.
exports.make = function(instance, config, element) {}| Parameter | Typ | Beschreibung |
|---|---|---|
instance |
Object |
The widget on the dashboard. |
config |
Object |
The settings of the widget. |
element |
jQuery |
The element to draw into. |
Dashboard calls it for each widget of this type. Define the handlers of instance here and draw the first content.
method
instance.dataset(item, callback)
Loads the chart data of one entry of the Dataset setting.
instance.dataset(item, callback)| Parameter | Typ | Beschreibung |
|---|---|---|
item |
Object |
One entry of config.dataset. |
callback |
Function |
function(response) with the list of series. |
The callback receives a list of series. Each series has id, name, icon, color, format, decimals and data, a list of points with x and y. See Chart data.
instance.dataset(config.dataset[0], function(response) {
for (var serie of response)
console.log(serie.name, serie.data.length);
});
event
instance.configure = function() {}
Runs after someone saves the settings of the widget.
instance.configure = function() {}Reload the data here, because config now holds the new settings.
event
instance.service = function(counter) {}
Runs every second while the dashboard is open.
instance.service = function(counter) {}| Parameter | Typ | Beschreibung |
|---|---|---|
counter |
Number |
The number of seconds since the dashboard opened. |
Use it for a refresh interval: reload when counter % config.interval === 0.