Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
Use the following code to get a UI component instance:

<!--JavaScript-->
var chartInstance = $("#chartContainer").dxChart("instance");
<!-- tab: index.js -->
var chartInstance = $("#chart-container").dxChart("instance");

If the UI component is not yet instantiated, this code throws an [E0009](/api-reference/50%20Common/utils/zz%20Errors%20and%20Warnings/E0009.md '/Documentation/ApiReference/Common/utils/Errors_and_Warnings/#E0009') exception that you can handle with a [try...catch](https://www.w3schools.com/js/js_errors.asp) block:

<!--JavaScript-->
<!-- tab: index.js -->
try {
var chartInstance = $("#chartContainer").dxChart("instance");
var chartInstance = $("#chart-container").dxChart("instance");
}
catch (err) {
alert("Exception handled: " + err.message);
}

Instead of the exception, you can get a truthy or falsy value that can be used in conditional statements. To do this, call the UI component class's static **getInstance(element)** method. This method returns **undefined** if the UI component is not instantiated for the element:
Instead of an exception, you can get a truthy or falsy value for use in conditional statements. Call the UI component classs static **getInstance(element)**. This method returns **undefined** if no UI component instance is associated with the element:

<!--JavaScript-->
var element = document.getElementById("chartContainer");
<!-- tab: index.js -->
var element = document.getElementById("chart-container");
var chartInstance = DevExpress.viz.dxChart.getInstance(element);
if (chartInstance) {
// Your code goes here
}
}

You can also get component instances in event handlers such as **onInitialized** or **onOptionChanged**:

<!-- tab: index.js -->
$('#data-grid-container').dxDataGrid({
onInitialized(e) {
let dataGridInstance = e.component;
// ...
}
// ...
})
Loading