DevExtreme jQuery - Get and Set Options
All operations with widget options are carried out using the option() method. You can use it to do the following.
Get All Options
var menuInstance = $("#menuContainer").dxMenu("instance"); var menuOptions = menuInstance.option(); // ---------- or ---------- var menuOptions = $("#menuContainer").dxMenu("option");
Get the Value of a Single Option
var menuInstance = $("#menuContainer").dxMenu("instance"); var menuDataSource = menuInstance.option("dataSource"); var submenuMode = menuInstance.option("showSubmenuMode.name"); // ---------- or ---------- var menuDataSource = $("#menuContainer").dxMenu("option", "dataSource"); var submenuMode = $("#menuContainer").dxMenu("option", "showSubmenuMode.name");
Set a Single Option
var menuInstance = $("#menuContainer").dxMenu("instance"); menuInstance.option("dataSource", []); menuInstance.option("showSubmenuMode.name", 'onClick'); // ---------- or ---------- $("#menuContainer").dxMenu("option", "dataSource", []); $("#menuContainer").dxMenu("option", "showSubmenuMode.name", 'onClick');
Set Several Options
var menuInstance = $("#menuContainer").dxMenu("instance"); menuInstance.option({ dataSource: [], showSubmenuMode: { name: 'onClick' } }); // ---------- or ---------- $("#menuContainer").dxMenu({ dataSource: [], showSubmenuMode: { name: 'onClick' } });
When you pass an object to the option(options) method or to the jQuery plugin at runtime as shown in the previous code, options specified in this object will be merged with the options that were specified at design time.
This works properly unless the options were specified as arrays. In this case, you should reassign the entire array of objects that contain new option values alongside old values. The following code sample demonstrates the described technique by the example of the valueAxis array in the Chart widget:
// Declare the array of objects that configure value axes var valueAxisConfigs = [{ name: "axis1", // ... }, { name: "axis2", // ... }]; $("#chartContainer").dxChart({ // .... // Assign the array to the valueAxis option valueAxis: valueAxisConfigs }); // Change an option in the first object from the array valueAxisConfigs[0].visible = false; // Reassign the whole array $("#chartContainer").dxChart({ valueAxis: valueAxisConfigs });
See Also
- API Reference.WidgetName.Configuration, for example, API Reference.Menu.Configuration
- Create and Configure a Widget - jQuery
If you have technical questions, please create a support ticket in the DevExpress Support Center.