是否可以将图标添加到 CRM 中的子网格?

Is it possible to add icons to a subgrid in CRM?

是否可以将图标添加到 CRM 中的子网格?我已尝试 this 解决方案,但图标不会出现在子网格中,仅用于视图。

编辑

我发现在进入子网格所在的页面之前打开关联视图的页面时,子网格中会出现图标。

我查看了打开这些页面时加载的资源。打开关联视图的页面时,将加载图像。打开子网格所在页面时不加载。有没有一种简单的方法可以在打开页面时将图像加载到 contentIFrame 中?

Image loaded when opening page for associated view

This blog 状态子网格图标偶尔显示。从上下文菜单中单击 'Refresh list' 有时可以解决问题。仍然不是 100% 有成果。

作为一种受支持的解决方法,您可以在 IFRAME 中显示带有图标的关联视图,如所讨论的那样 here

实施时this solution, subgrid icons appears sporadically after refreshing the subgrid. What's actually happening is that Dynamics is adding a div with the class ms-crm-Grid-DataColumn-ImgItem. This div contains an img element, sometimes with a src and most of the times with no src at all, example here.

我已经为此开发了一个适用于 Dynamics 365 的解决方法,但 Microsoft 非常不支持。请访问 this page 并对该问题进行投票,以便我们获得支持的解决方案。

//This function is called when form is loaded
function refreshSubgridIcons() {

  var grid = Xrm.Page.ui.controls.get('SUBGRID_NAME');

  if (grid == null) {
     setTimeout(function () { refreshSubgridIcons(); }, 5000);
     return;
  }

  //This function will be called everytime subgrid is refreshed/loaded
  grid.addOnLoad(setSubgridIcons);

}

function setSubgridIcons() {

  //Get active IFrame
  var contentIFrame = window.top.document.getElementById(getActiveIFrame());

  //Get subgrid
  var subgrid = contentIFrame.contentWindow.document.querySelector('[gridid="SUBGRID_NAME"]');

  //Wait for rows to be loaded
  setTimeout(function () { 
    //Get rows in subgrid
    var subgridRows = subgrid.getElementsByClassName('ms-crm-List-Row-Lite');

    //Loop through all rows in subgrid
    for (i = 0; i < subgridRows.length; i++) {
        //Get priority for row
        var priority = subgridRows[i].querySelector('[rawvalue]');
        var priorityValue = priority.getAttribute('rawvalue');

        //Set image url depending on priority value for row
        var imgUrl;
        if (priorityValue == '1') {
            imgUrl = 'URL_FOR_IMAGE_HIGH';
        }
        if (priorityValue == '2') {
            imgUrl = 'URL_FOR_IMAGE_MEDIUM';
        }
        if (priorityValue == '3') {
            imgUrl = 'URL_FOR_IMAGE_HIGH';
        }

        var nobr = subgridRows[i].getElementsByTagName('nobr');
        //Get div for img
        var imgItem = nobr[0].getElementsByClassName('ms-crm-Grid-DataColumn-ImgItem');

        if (imgItem.length == 0) {
            //Create div and img if not exists
            var div = document.createElement('div');
            div.setAttribute('class', 'ms-crm-Grid-DataColumn-ImgItem');
            div.innerHTML = '<img src="' + imgUrl + '"/>';
            nobr[0].insertBefore(div, nobr[0].firstChild);

        } else {
            //Change src on existing img
            var img = imgItem[0].getElementsByTagName('img');
            img[0].setAttribute('src', imgUrl);
        }

    }

}, 100);

}

function getActiveIFrame() {
  //Get all IFrames in the page
  var IFrames = window.top.document.querySelectorAll('iframe');

  //Get active IFrame
  var IFrame;
  for (i = 0; i < IFrames.length; i++) {
      if (IFrames[i].style.visibility == 'visible') {
          IFrame = IFrames[i].id;
      }
  }
  return IFrame;
}