Using Extension Functions
Using an Extension Function works much like using an Event Handler. First select and Enable the Extension Function within the component scripting window, and then add in a script. The script will then automatically run when called.
Example - Power Table Component
The Power Table component has several extension functions on it that change the way the table looks or behaves. One in particular, called
onPopupTrigger(), makes it easy to implement a right click popup menu as it is called each time a user right clicks on a cell of the table. It can be used in conjunction with the system.gui.createPopupMenu function to create your own custom popup menu. When the Power Table is first created in a window, it will have a pre-built example commented out in the extension function. Simply uncomment the lines of code, and see it in action! It helps to set the Test Data property for the Power Table so you have some data to test on.
Clicking on the "Hello" menu option will have a message box appear that has the value of the cell that was right clicked.
Example - Table Component
The Table component exposes an Extension Function called
getBackgroundAt(). By implementing this function, you can control the background color of each cell of the table component using scripting. Starting with the Table component, we can add in some test data using the TestData property, and then add the following script to the
getBackgroundAt() Extension Function.
The script allows us to change the background color of the component based on the value of the cell in Col 1 for that row. After clicking the OK button to save our script, you should see the script run automatically, and the background color of the table will change.
Example - User Management Component
The User Management component has many Extension Functions that provide a way to customize how the component works. The
filterUser() extension function is useful for filtering out users you don't want to see in the user source, preventing users from editing that user in the client. We can add a simple script to the
filterUser() Extension Function that will hide the user from the list if they have the Administrator role.
By enabling this script, we now only see the users without the Administrator role in the list of users.
Example - Ad Hoc Charting
The Easy Chart component has an Extension Function to allow scripting when a Tag is dropped onto it (see Ad Hoc Charting). There is a lot of customization possible in the designer but any client side changes to the Tag Pens dataset must be done here. Generally, people want to change what axis and subplot a pen goes into based on some other information. Below is a simple example that uses the Tag's name to determine this. For this example to work you need to have two subplots and a second axis named "HOA".