https://msdn.microsoft.com/en-us/library/dn932126.aspx#BKMK_GridControl

Updated: November 29, 2016

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.

In this topic

 
GridControl

Events and methods for the GridControlOnLoad eventaddOnLoadgetEntityNamegetGridgetViewSelector and removeOnLoad.

Grid

Methods for the Grid returned by the GridControl.getGrid method: getRowsgetSelectedRows, and getTotalRecordCount.

GridRow

The getData method for the GridRow returned by the Grid.getRows and Grid.getSelectedRows methods.

GridRowData

The getEntity method for the GridRowData returned by the GridRow.getData method.

GridEntity

Methods for the GridEntity returned by the GridRowData.getEntity method: getEntityNamegetEntityReferencegetId, andgetPrimaryAttributeValue.

ViewSelector

Methods for the ViewSelector returned by the GridControl.getViewSelectorgetCurrentViewisVisible and setCurrentView

GridControl

 

Before CRM Online 2015 Update 1 the only unique method for the subgrid control was refresh. When you know the name of the subgrid control you can access it using the following code, for example, to access the CONTACTS subgrid in the default account form.

 
 
var contactsSubgrid = Xrm.Page.getControl("Contacts");
Tip

To identify the names of subgrid controls in the form without opening the form editor, see the information in Use browser developer tools.

As an Xrm.Page.ui control, GridControl also has all the standard control methods: getControlTypeLabel methods, getParentVisible methods,setFocus, and Notification methods as well as refresh. See Xrm.Page.ui control (client-side reference) for more information on these methods.

OnLoad event

 

Add event handlers to this event to run every time the subgrid refreshes. This includes when users sort the values by clicking the column headings. Use the GridControl.addOnLoad and GridControl.removeOnLoad methods to manage event handlers, usually in the form Onloadevent.

addOnLoad

 

Use this method to add event handlers to the GridControlOnLoad event.

Parameter type: Function

Example: Add the myContactsGridOnloadFunction function to the Contacts subgrid OnLoad event.

 
var myContactsGridOnloadFunction = function () { console.log("Contacts Subgrid OnLoad occurred") };
Xrm.Page.getControl("Contacts").addOnLoad(myContactsGridOnloadFunction);

getEntityName

 

Use this method to get the logical name of the entity data displayed in the grid.

Return value type: String

Example: Set the opportunitySubgrids variable to an array of subgrid controls that display opportunity records.

 
var opportunitySubgrids = Xrm.Page.getControl(function (ctrl, i) {
if (ctrl.getControlType() == "subgrid") {
return (ctrl.getEntityName() == "opportunity");
}
else {
return false;
}
})

getGrid

 

Use this method to get access to the Grid available in the GridControl.

Return value type:Grid

Example: Set the contactsSubgridGrid variable to the grid of the Contacts subgrid.

 
var contactsSubgridGrid = Xrm.Page.getControl("Contacts").getGrid();

getViewSelector

 

Use this method to get access to the ViewSelector available for the GridControl.

Return value type:ViewSelector

Example: Set the contactsSubgridViewSelector variable to the view selector of the Contacts subgrid.

 
var contactsSubgridViewSelector = Xrm.Page.getControl("Contacts").getViewSelector();

removeOnLoad

 

Use this method to remove event handlers from the GridControlOnLoad event.

Parameter type: Function

Example: Add the myContactsGridOnloadFunction function to the Contacts subgrid OnLoad event and then remove it.

 
var myContactsGridOnloadFunction = function () { console.log("Contacts Subgrid OnLoad occurred") };
Xrm.Page.getControl("Contacts").addOnLoad(myContactsGridOnloadFunction);
Xrm.Page.getControl("Contacts").removeOnLoad(myContactsGridOnloadFunction);

Grid

 

Use Grid methods to access information about data in the grid. Grid is returned by the GridControl.getGrid method.

getRows

 

Returns a collection of every GridRow in the Grid.

Return value type: Collection

Example: Set the allRows variable to a collection of GridRow from the Contacts subgrid.

 
var allRows = Xrm.Page.getControl("Contacts").getGrid().getRows();

Remarks:

See Collections (client-side reference) for information on the methods available to access data in a collection.

getSelectedRows

 

Returns a collection of every selected GridRow in the Grid.

Return value type: Collection

Example: Populate the selectedEntityReferencesArray variable with entity references for selected rows from the Contacts subgrid.

 
 
//Get an array of entity references for all selected rows in the subgrid
var selectedEntityReferences = [];
var selectedRows = Xrm.Page.getControl("Contacts").getGrid().getSelectedRows();
selectedRows.forEach(function (selectedRow, i) {
selectedEntityReferences.push(selectedRow.getData().getEntity().getEntityReference());
});

Remarks:

See Collections (client-side reference) for information on the methods available to access data in a collection.

getTotalRecordCount

 

In the web application or the Dynamics 365 for Outlook client while connected to the server, this method returns the total number of records that match the filter criteria of the view, not limited by the number visible in a single page.

When the Dynamics 365 for Outlook client isn’t connected to the server, this number is limited to those records that the user has selected to take offline.

For Microsoft Dynamics 365 for tablets and Microsoft Dynamics 365 for phones this method will return the number of records in the subgrid.

Return value type: Number

Example: Set the filteredRecordCount variable to the total number of records that match the filter criteria of the view.

 
var filteredRecordCount = Xrm.Page.getControl("Contacts").getGrid().getTotalRecordCount();

GridRow

 

Use the GridRow.getData method to access the GridRowData. A collection of GridRow is returned by Grid.getRows and Grid.getSelectedRowsmethods.

getData

 

Returns the GridRowData for the GridRow.

Return value type:GridRowData

Example: Populate the allGridRowDataArray variable with GridRowData for all rows from the Contacts subgrid.

 
var allGridRowData = [];
var rows = Xrm.Page.getControl("Contacts").getGrid().getRows();
rows.forEach(function (row, i) {
allGridRowData.push(row.getData());
});

GridRowData

 

Use the GridRowData.getEntity method to access the GridEntityGridRowData is returned by the GridRow.getData method.

getEntity

 

Returns the GridEntity for the GridRowData.

Return value type:GridEntity

Example: Populate the allGridEntitiesArray variable with GridEntity for all rows from the Contacts subgrid.

 
var allGridEntities = [];
var rows = Xrm.Page.getControl("Contacts").getGrid().getRows();
rows.forEach(function (row, i) {
allGridEntities.push(row.getData().getEntity());
});

GridEntity

 

Use the GridEntity methods to access data about the specific records in the rows. GridEntity is returned by the GridRowData.getEntity method.

getEntityName

 

Returns the logical name for the record in the row.

Return value type: String

Example: Set the firstEntityType variable to the value of the entity logical name for the first row in the Contacts subgrid.

 
var firstEntityType = Xrm.Page.getControl("Contacts").getGrid().getRows().get(0).getData().getEntity().getEntityName();
// firstEntityType == "contact"

getEntityReference

 

Return value type: Lookup

Example: Set the firstEntityType variable to an entity reference for the first row in the Contacts subgrid.

 
var firstEntityReference = Xrm.Page.getControl("Contacts").getGrid().getRows().get(0).getData().getEntity().getEntityReference();
// firstEntityReference.entityType == "contact"
// firstEntityReference.id == "{13CD16BD-3EC4-E411-80CF-00155DB58496}"
// firstEntityReference.name == "Rene Valdes (sample)"

Remarks:

This lookup has the following properties:

Name

Type

Description

entityType

String

The logical name for the record in the row. The same data returned by the GridEntity.getEntityNamemethod.

id

String

The id for the record in the row. The same data returned by the GridEntity.getId method.

name

String

The primary attribute value for the record in the row. The same data returned by theGridEntity.getPrimaryAttributeValue method.

getId

 

Returns the id for the record in the row.

Return value type: String

Example: Set the firstEntityId variable to the value of id of the record from the first row in the Contacts subgrid.

var firstEntityId = Xrm.Page.getControl("Contacts").getGrid().getRows().get(0).getData().getEntity().getId();
// firstEntityId == "{13CD16BD-3EC4-E411-80CF-00155DB58496}"

getPrimaryAttributeValue

 

Returns the primary attribute value for the record in the row.

Return value type: String

Example: Set the currentView variable to the current view of the view selector for the Contacts subgrid.

 
var firstEntityPrimaryAttributeValue = Xrm.Page.getControl("Contacts").getGrid().getRows().get(0).getData().getEntity().getPrimaryAttributeValue();
// firstEntityPrimaryAttributeValue == "Rene Valdes (sample)"

ViewSelector

 

Use the ViewSelector methods to get or set information about the view selector of the subgrid control.

Note

If the subgrid control is not configured to display the view selector, calling the ViewSelector methods will throw an error.

getCurrentView

 

Use this method to get a reference to the current view.

Return value type: Lookup object

Example: Set the currentView variable to the current view of the view selector for the Contacts subgrid.

 
var currentView = Xrm.Page.getControl("Contacts").getViewSelector().getCurrentView();

Remarks:

If the subgrid control is not configured to display the view selector, calling this method on the ViewSelector returned by theGridControl.getViewSelector method will throw an error.

isVisible

 

Use this method to determine whether the view selector is visible.

Return value type: Boolean

Example: Set the viewSelectorIsVisible variable to represent the visibility status of the view selector for the Contacts subgrid.

 
var viewSelectorIsVisible = Xrm.Page.getControl("Contacts").getViewSelector().isVisible();

Remarks:

If the subgrid control is not configured to display the view selector, calling this method on the ViewSelector returned by theGridControl.getViewSelector will throw an error.

setCurrentView

 

Use this method to set the current view.

Parameter type: Lookup object

Example: Set the ContactsIFollow variable to be the current view of the Contacts subgrid.

 
var ContactsIFollow = {
entityType: 1039, // SavedQuery
id:"{3A282DA1-5D90-E011-95AE-00155D9CFA02}",
name: "Contacts I Follow"
}
//Set the view using ContactsIFollow
Xrm.Page.getControl("Contacts").getViewSelector().setCurrentView(ContactsIFollow);

Remarks:

If the subgrid control isn’t configured to display the view selector, calling this method on the ViewSelector returned by theGridControl.getViewSelector will throw an error.

This Lookup has the following properties:

Name

Type

Description

entityType

Number

The object type code for the SavedQuery (1039) or UserQuery (4230) that represents the view the user can select.

id

String

The ID for the view the user can select.

name

String

The name of the view the user can select.

Grid (read-only) objects and methods (client-side reference)获取子表单对象的一些方法 Crm 2016的更多相关文章

  1. 关于client浏览器界面文字内容溢出用省略号表示方法

    在实际的项目中,因为client浏览器文字内容的长度不确定性和页面布局的固定性,难免会出现文字内容超过div(或其它标签,下同)区域的情况.此时比較好的做法就是当文字超过限定的div宽度后自己主动以省 ...

  2. [SharePoint]javascript client object model 获取lookup 类型的field的值,包括user类型(单人或者多人)的值。how to get the multiple user type/lookup type field value by Javascript client object model

    1. how to get value var context = new SP.ClientContext.get_current(); var web = context.get_web(); v ...

  3. Dynamics 365中的Client API form context (formContext)

    适用于Dynamics 365 for Customer Engagement apps 9.x版本. 本文是一篇翻译,原文来源是微软官方文档. 本文链接:https://www.cnblogs.co ...

  4. Bluetooth 4.0之Android 解说

     Android平台包括了对蓝牙网络协议栈的支持,它同意一个蓝牙设备跟其它的蓝牙设备进行无线的数据交换.应用程序通过Android蓝牙API提供訪问蓝牙的功能. 这些API会把应用程序无线连接到其 ...

  5. Unit Testing of Spring MVC Controllers: “Normal” Controllers

    Original link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...

  6. SpringDataRedis入门到深入

    一:简介 SpringDataRedis是SpringData开源项目中的一部分,它可以在Spring项目中更灵活简便的访问和操作Redis:原先在没有SpringDataRedis时往往使用Jedi ...

  7. Django ORM、一对一、一对多、多对多、详解

    上篇博客也提到这些知识点,可能大家还是不太清楚,这篇博客为大家详细讲解ORM中的几个知识点 1.1首先我们先看一个小案例: #_*_coding:utf-8_*_ from django.db imp ...

  8. Python Day20

    Django 表操作 1.基本操作 # 增 # # models.Tb1.objects.create(c1='xx', c2='oo') 增加一条数据,可以接受字典类型数据 **kwargs # o ...

  9. Python自动化之一对多

    一对多 建立一对多关系之后(也就是加了外键),会在字表里面多一个"外键字段_id"这个字段 查询 #_*_coding:utf-8_*_ from django.db import ...

随机推荐

  1. zendstudio的安装与配置

    <微信公众平台应用开发实战>第1章搭建开发环境和相关技术介绍,本章会先介绍微信公众平台的一些基本概念和公众平台的开发模式:然后讲解如何搭建开发环境—AppServ和zendstudio:然 ...

  2. 使用print2flash开发在线文档

    www.print2flash.com 命令行调用: A:\Program Files (x86)\Print2Flash3>p2fServer.exe a.pdf a.swf

  3. jstat undocumented

    jstat -J-Djstat.showUnsupported=true -name btrace.com.sun.btrace.samples.ThreadCounter.count 11674 h ...

  4. 原创:LoadTest系列之Insert Condition

    当脚本中的部分内容需要满足某些条件后才执行时,则可以使用Insert Condition,例如有如下操作: 操作1:登录 操作2:添加一条数据: 在这两个操作中,只有操作1成功后,操作2才有意义,这时 ...

  5. dashboard项目心得:

    DAO类实现查找数据并放入一个map public Map<String,Integer> getAllBlock_multi(String projectname){ LinkedHas ...

  6. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  7. Quick Cocos2dx MVC初步

    今天看到了自己之前两年前写的一个地图编辑器, 写了不到一半就放弃了, 但是还是github上的小伙伴fork了, 真的感觉对不起那位伙计, 同时也鄙视一下一直以来懒得要死的自己, 希望这个demo不要 ...

  8. CSDN泄漏数据完整分析

    CSDN泄漏数据完整分析 2011-12-22 08:59:26 53391 次阅读 0 条评论 感谢mayee的投递 昨天CSDN的用户数据库被人在网上公布.我下载分析了下里面的数据,得出了一些很有 ...

  9. POJ3169差分约束系统

    题意:有n头牛,编号为1到n,对于关系好的ml头牛,al和bl之间的距离不大于dl,关系差的md头牛,ad和bd之间的距离不大于dd,求第1头牛和第n头牛之间的距离 分析:这是一道差分约束系统的题目, ...

  10. 《C程序设计语言》读书笔记----习题1-21

    题目就不写了,大概意思就是:尽量用制表符'\t'替换掉字符串中的空格. 同学们需要注意的是,打印一个制表符'\t',其所占长度不是固定的. 这里要理解“制表符”和“制表符终止位”.“制表符”的作用是使 ...