Mashup Builder > Widgets > Standard Widgets > Toolbar Widget (Themable) > Example: Sample Toolbar Configuration
Example: Sample Toolbar Configuration
Creating a Data Service
1. In Composer, create a Thing or Thing Template, and then open the Services tab.
2. Click Add to create a new service for the toolbar.
3. Under Service Info, type a name for the service, and then click Save and Continue.
4. In the code editor, define a new infotable using the ToolbarAction Data Shape.
Optionally, you can use the available code snippets:
a. In the left pane, expand Snippets. Under Code Snippets, expand Infotable.
b. Select the Create Infotable from datashape snippet to create an infotable. A dialog box opens.
c. In the dialog box, select the ToolbarAction data shape, and then click Insert Code Snippet. The code snippet is added to the code editor.
5. Define the toolbar actions by adding rows with values for each infotable field using the data shape. The syntax to define a row is as follows:
<infotable_name>.AddRow(<Row_Object>);
6. When you finish defining your service, click Done.
7. Click Save to save the changes to the entity.
* 
Click Execute to preview the returned output from the data service.
Creating the Actions Infotable
The following data service shows an example to create a toolbar using the ToolbarAction data shape.
In the first section, create an infotable using the CreateInfoTableFromDataShape() method:
var toolbarData = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(toolbarData);
Next, define the toolbar actions using the options that are available for the action type in the ToolbarAction data shape. You can pass the data field values as JSON objects using the AddRows() infotable method. Store the infotable data in a variable named result. The following service defines an infotable that contains several actions for the Toolbar widget.
var toolbarData = {

infoTableName: "InfoTable",
dataShapeName : "ToolbarAction"

};

var toolbarData = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(toolbarData);

// Link Action
toolbarData.AddRow({
actionId: "L1",
actionType: "link",
actionLabel: "Link",
actionTooltip: "A link to an external resource.",
actionDisabled: false,
actionVisible: true,
linkDestination: 'https://www.ptc.com/',
linkType: "Primary",
actionMaxWidth: 100
});

// Toggle Button Action
toolbarData.AddRow({
actionId: "T1",
actionType: "toggle",
actionLabel: "Hide Header",
actionTooltip: "Hides the grid header row.",
actionDisabled: false,
actionVisible: true,
toggleChipIcon: true,
toggleState: false,
toggleLabelPosition: 'left',
actionMaxWidth: 160
});

// Dropdown Action
toolbarData.AddRow({
actionId: "DD2",
actionType: "dropdown",
actionLabel: "Row Height:",
actionTooltip: "Controls the height of the body rows.",
actionDisabled: false,
actionVisible: true,
dropdownLabelPosition: "left",
dropdownData: [{label:" Compact 32px", value: "32"}, {label:"Default 48px", value: "48"}, {label:"Tall 64px", value: "64"}],
dropdownSelectedText: "48",
actionMaxWidth: 220,
alignRight: true
});

// Button Action
toolbarData.AddRow({

actionId: "B1",
actionType: "button",
actionLabel: "Edit",
actionTooltip: "The tooltip for the Edit button.",
buttonIcon: "ResetIcon",
actionDisabled: true,
actionVisible: true,
buttonType: "transparent",
actionMaxWidth: 140,
alignRight: true,

});

// Button Action
toolbarData.AddRow({
actionId: "B2",
actionType: "button",
actionLabel: "Reset",
actionTooltip: "The tooltip for the Reset button.",
actionDisabled: false,
actionVisible: true,
buttonType: "transparent",
buttonIcon: "EditIcon",
actionMaxWidth: 140,
alignRight: true
});

result=toolbarData;
The following image shows the infotable output after the data service is executed:
The infotable contains five rows that are used to define and configure five actions. The following image shows the actions on the Toolbar widget at run time.
The actions are displayed in different regions on the toolbar, depending on their order in the infotable and the value of the alignRight option. You can create toolbars with various configurations to provide compact controls for widgets, services, or functions in a mashup. For example, you can create bindings between the Toolbar widget and a Grid widget to configure and filter a grid at run time.
Was this helpful?