Write scripts for subgrids
Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online
You can set event handlers to execute scripts when data is loaded in subgrids. This provides methods to change the selected view and get references to data displayed in the grid.
Important
This feature was introduced in CRM Online 2015 Update 1 and CRM 2016 (on-premises).
In this topic
Subgrid OnLoad event
Subgrid object model
Subgrid OnLoad event
Subgrids load asynchronously from the form so you can’t reliably get access to the data in the subgrid in the form OnLoad event. But you can set an event handler for the OnLoad event of the subgrid. This event will occur each time the data in the grid is refreshed, this includes when users sort the columns of the grid.
There is no user interface to add new event handlers for this event, so if you want to do so, you must use code in another event, typically the form OnLoad event to use the GridControl.addOnLoad method. To remove event handlers for this event, use the GridControl.removeOnLoad method.
Subgrid object model
The diagram below shows the objects you can access from a subgrid in a form.
The subgrid control is referred to as a GridControl in this context. As an Xrm.Page.ui control, the subgrid has all the methods available to all controls in addition to the refresh method.
The GridControl is the same object passed to a command bar or ribbon actions or rules using the <CrmParameter> (RibbonDiffXml) when available when the SelectedControl parameter is selected.
Change views with the ViewSelector
When a subgrid is configured to display a view selector you can get or set the current view. Use the GridControl.getViewSelector method to access the view selector and then the ViewSelector.getCurrentViewgetCurrentView and ViewSelector.setCurrentView methods to get or set the current view with a lookup object.
Get data from the grid
Use the GridControl.getGrid method to access the grid. Use the Grid.getRows method or Grid.getSelectedRows method to get a collection of GridRow objects. You can then access a reference to each record in the row by chaining together the GridRow.getData, GridRowData.getEntity, and GridEntity.getEntityReference methods.
See Also
Grid (read-only) objects and methods (client-side reference)
Collections (client-side reference)
Write code for Microsoft Dynamics 365 forms
Extend Microsoft Dynamics 365 on the client
Microsoft Dynamics 365
© 2016 Microsoft. All rights reserved. Copyright