3.2. Modifying the JavaScript adapter class

3.2.1. Removing the text property descriptor

In the previous article, we created a Text property that displayed the main text for the sticky note. The data visualization version of this sample will leave out this property as it will determine the text using data binding:

3.2.2. Defining the supported settings

To allow the adapter to handle data, the getSupportedSettings method must be overridden. This method returns an object with the variety of settings available for the adapter. In the following example, we indicate that we support data for a single metric set, and do not allow styles to be applied:

Implementers of this function should call this._super() first to get the default settings.

3.2.3. Overriding request options

Totals are normally added to the metric set's data result by default. The sticky note adapter would then read this total as the first row, but this is not the desired behavior. The image below illustrates this difference:

To override the metric set and disable totals regardless of user settings, the _getDataRequests method (considered a protected method) is overridden. The following demonstrates how to override the _getDataRequests method on the adapter to turn off totals:

3.2.4. Setting up bindings

This is optional: state indicators have no bindings, for example. Bindings are specifically for users to be able to customize where and which data is displayed.

Data visualizations in Dundas BI display data from a metric set, and typically use a set of bindings that specify how the various parts of the data visualization are connected to data elements.

Users can use these bindings to decide for themselves whether each measure or hierarchy is visualized and where. These are set up in the Visualization tab of the Data Analysis Panel (see Setting up the visualization for details).

In order to make bindings available, you need to override the getAvailableBindings Method. In the following example, we return a list of one text binding:

getAvailableBindings: function (metricSetBinding, node) {
/// <summary>
/// Gets the available bindings for this adapter.
/// </summary>
/// <param name="metricSetBinding" type="dundas.view.controls.MetricSetBinding">The metric set binding to get the bindings for.</param>
/// <param name="node" type="dundas.controls.ExplorerNode" optional="true">(optional) The node that should be used for getting the available bindings.</param>
/// <returns type="Array" elementType="Object">An array of plain objects with properties:
/// targetId [type: String] - A unique identifier for this binding.
/// targetName [type: String] - The displayed text for this binding.
/// bindingType [type: dundas.data.PlacementPosition, optional: true] - (optional) The placement that should be assigned to an analysis element dropped onto this binding. If not specified, it is assigned to rows.
/// iconUrl [type: String, optional: true] - (optional) A URL pointing to the icon image to be shown next to the header.
/// tooltipText [type: String, optional: true] - (optional) Any tooltip text that should be shown for this binding header.
/// propertyPath [type: Array, elementType: dundas.view.controls.PropertyPathItem, optional: true] - (optional) If specified, the property path will be linked to the binding with a small icon to allow it to quickly open in the properties.
/// groupName [type: String, optional: true] - (optional) The group name for the binding. If set, the binding can be grouped.
/// isAdvanced [type: Boolean, optional: true] - (optional) If specified, the binding is advanced and will be not displayed within the group by default, but rather as 'more...'. This only applies if groupName is specified.
/// rect [type: dundas.view.controls.Rect, optional: true] - (optional) The rectangle co-ordinates for the adorner to display for drop-zones on this adapter.
/// </returns>
return [{
"targetId": "text",
"targetName": "Text"
}];
},

The visualization can automatically assign bindings when data is added to it, so that users don't necessarily need to also assign the data themselves, by overriding the generateBindings method. In the following example, data is automatically assigned under Text when added:

generateBindings: function (options) {
/// <summary>
/// Asks the adapter to create/update the bindings on the given MetricSetBinding.
/// The _super method should be called first if automatic adding/removal is desired from metricSetBindings property, and bindings created/removed.
/// </summary>
/// <param name="options" type="Object">The options object for the creation of the bindings. Structure:
/// metricSet [type: dundas.entities.MetricSet] - The metric set object that is the source of the metric set binding.
///
/// metricSetBinding [type: dundas.view.controls.MetricSetBinding] - The metric set binding that is being modified.
///
/// addedElements [type: Array, elementType: Object] - (optional) An array of objects describing what is being added.
/// elementUsage [type: dundas.data.AnalysisElementUsage] - The element usage from within the metric set that is the column.
/// bindingId [type: String] - (optional) The binding ID that the element was added for.
/// bindingName [type: String] - (optional) The binding name that the element was added for.
/// levelUniqueName [type: String] - (optional) The level unique name that this element is for.
///
/// removedElements [type: Array, elementType: Object] - (optional) An array of objects describing what is being removed.
/// elementUsage [type: dundas.data.AnalysisElementUsage] - The element usage from within the metric set that is the column.
///
/// adapterData [type: Object] - (optional) An object specified as the adapter data for the requested adapter info class.
/// </param>
var addedElements = options.addedElements;
if (!addedElements || !addedElements.length) {
// The entire metric set was added.
addedElements = options.metricSet.elements.map(function (elementUsage) { return { elementUsage: elementUsage }; });
}
addedElements.forEach(function (addedElement) {
// Bind to only row hierarchies and measures for now
if (addedElement.elementUsage.placement == dundas.data.PlacementPosition.ROWS
|| addedElement.elementUsage.placement == dundas.data.PlacementPosition.MEASURE) {
// Some elements have options to be hidden.
if (!addedElement.elementUsage.isHidden && !addedElement.elementUsage.isNotVisualized) {
// If the user picked no specific binding binding target, or they picked Text:
if (!addedElement.bindingId || addedElement.bindingId == "text") {
// Generate a binding.
options.metricSetBinding.bindings.push(new dundas.view.controls.Binding({
elementUsageUniqueName: addedElement.elementUsage.uniqueName,
targetId: "text",
targetName: "Text"
}));
}
}
}
}, this);
},

3.2.5. Loading data

The sticky note text is set by overriding the loadData method. In the example below, the _getData method is called to request the data, and the DataResult that is returned and set on the metric set binding is used to display the text: