Custom Code
Custom code allows you to access the panel's options, REST API responses, form elements, and various Grafana services.
Custom code is executed after the Initial
and Update
requests, when Element Value Changed
.
Parameters
Parameter | Description | Initial, Update | Change Value | ShowIf, DisableIf, Get Options |
---|---|---|---|---|
context.element | Current element | ✔️ | ||
context.panel.data | Result set of panel queries. | ✔️ | ✔️ | ✔️ (For Get Options ) |
context.panel.elements | Form elements. | ✔️ | ✔️ | ✔️ |
context.panel.initial | Parsed values from the initial request. | ✔️ | ✔️ | |
context.panel.initialRequest() | Performs an initial request to reload the panel. | ✔️ | ✔️ | |
context.panel.options | Panel's options. | ✔️ | ✔️ | |
context.panel.onOptionsChange({}) | Modifies a handler to refresh the panel. | ✔️ | ✔️ | |
context.panel.onChangeElements([]) | Updates elements in the local state. Change elements. Accepts an array of new elements. | ✔️ | ✔️ | |
context.panel.patchFormValue({}) | Update the value of the elements. Accepts an object. | ✔️ | ✔️ | |
context.panel.setFormValue({}) | Update the value of the elements. Accepts an object. If value is not passed to the element, the value should be used from initial or cleared. | ✔️ | ✔️ | |
context.panel.formValue() | Contains a current form value as object. | ✔️ | ✔️ | |
context.panel.response | Request's response. | ✔️ | ||
context.panel.setInitial({}) | Specifies initial values for a custom initial request to highlight modified values and requests a user's confirmation. | ✔️ | ||
context.panel.enableSubmit() | Enable Submit button | ✔️ | ✔️ | |
context.panel.disableSubmit() | Disable Submit button | ✔️ | ✔️ | |
context.panel.enableReset() | Enable Reset button | ✔️ | ||
context.panel.disableReset() | Disable Reset button | ✔️ | ||
context.panel.enableSaveDefault() | Enable Save Default button | ✔️ | ||
context.panel.disableSaveDefault() | Disable Save Default button | ✔️ | ||
context.panel.setError('Message') | Displays an error on panel. | ✔️ | ||
context.panel.sectionsUtils.add(section) | Add a new Section. Added in v4.9.0. | ✔️ | ✔️ | |
context.panel.sectionsUtils.update(sections) | Change Sections. Added in v4.9.0. | ✔️ | ✔️ | |
context.panel.sectionsUtils.remove(id) | Remove Section. Added in v4.9.0. | ✔️ | ✔️ | |
context.panel.sectionsUtils.assign(id, elements) | Assign elements to Section. Added in v4.9.0. | ✔️ | ✔️ | |
context.panel.sectionsUtils.unassign(elements) | Unassign elements from Section. Added in v4.9.0. |