The toolbar is implemented by a toolbar widget ,which is created by the interactive grid widget. To learn more about the toolbar widget, read library file widget.toolbar.js. That file documents the properties of the toolbar widget, the toolbarData array, control types and their properties.
toolbarData is an array that describes the toolbar – the buttons, fields and menus visible to the user, and their actions. Toolbar objects are grouped into control groups. Each control group has one or more controls, of type Static, Text, Select, Button, Menu, Radio Group or Toggle.
By default, the toolbarData is based on the Grid default options and declarative settings.
There are two general approaches to writing an override function:
- Totally replace
- Copy and adjust
That is, your custom configuration function can completely (re)define the toolbar, or, it can make adjustments to the default or current toolbarData. Which approach is best depends on your requirements – the degree of customization required.
If you are totally replacing, you can fill the array as you want. You might want to examine the default toolbarData to see what is possible.
If you are adjusting, you need to understand the default toolbarData array to know where to add your customization.
Default toolbarData Array
By default, for an editable grid, there are 7 control groups in the toolbar, as shown below:
Note that the reports, views, actions2 and actions3 toolbar groups are conditionally visible: the reports group becomes visible when there are multiple reports, the views group becomes visible when there are multiple views; the actions2 and actions3 groups become visible when edit mode is on.
To examine all of the elements in the toolbarData object (as well as all other objects of the interactiveGrid widget) use this command in the Console:
using the static id of your interactive Grid for “emp_igrid”. This command says, Show me the config options for the emp_igrid Interactive Grid region.
Examine the returned contents by clicking through all the objects. Look at the toolbarData object, expanding the elements beneath it. After a few clicks you will no doubt recognize menu and button elements of the interactive grid Actions menu and other toolbar features.
The default toolbarData array has 7 elements, for 7 control groups, shown below:
If we look at just “actions1” object, you will see that it is a menu containing the familiar elements of the Actions menu. This image shows the download dialog menu element expanded.
Let’s say our users do not like doing two clicks (Actions –> Download) to get to Download – they want a Download button on their toolbar. In fact, they want it all the way over to the right.
This function does the trick:
var $ = apex.jQuery,
toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),
toolbarGroup = toolbarData.toolbarFind("actions4"); // this IS the rightmost GROUP WITH the RESET button
// add a Download button next to the Reset button
config.toolbarData = toolbarData;
The toolbar stuff adds the button, with the action show-download-dialog. The show-download-dialog action is the same definition found while examining the actions menu.
- Copy the default toolbarData – we will make changes to a copy
- Get the actions4 toolbar group
- Add (Push) the download dialog to the actions4 toolbar group
- Copy the modified toolbar to the return config
Note that Download is a declarative option –
So, if/when a (the next?) developer sets Download Off … your newly-placed Download button disappears. The declarative nature of the show-download-dialog action is contained within the action – our moving the button around does not overwrite that declarative toggle.
One can also turn off Download (and other features) programmatically. To do so, we use this command:
config.features.download = false;
This simple example show how to add one button – you can of course add more, or redefine the entire toolbarData area. For additional, more complex toolbar customization examples, see the examples in the Sample Interactive Grid packaged application. And read the Interactive Grid posts in the HardLikeSoftware blog by John Snyders of the Oracle APEX team.
Interactive Grid is a great new region type – and it is still evolving. This writing is for APEX 5.1.2 – APEX 5.2 may bring more declarative options, and/or may bring documented APIs for customizing the toolbar – who knows. Stay tuned!