简体   繁体   English

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

[英]Is it possible to add icons to a subgrid in CRM?

Is it possible to add icons to a subgrid in CRM? 是否可以在CRM的子网格中添加图标? I have tried this solution but the icons won't appear in subgrid, only for the view. 我已经尝试过解决方案,但图标不会出现在子网格中,仅用于视图。

EDIT 编辑

I have noticed that the icon appears in the subgrid if I open the page for associated view before I go to the page where the subgrid is located. 我注意到,如果在转到子网格所在的页面之前打开用于关联视图的页面,则该图标会出现在子网格中。

I looked at what resources that are loaded when opening these pages. 我查看了打开这些页面时加载的资源。 When opening the page for associated view, image is loaded. 当打开用于关联视图的页面时,将加载图像。 It isn't loaded when opening the page where the subgrid is located. 打开子网格所在的页面时不会加载它。 Is there a easy way to load image into contentIFrame when opening the page? 打开页面时,是否有一种简单的方法可以将图像加载到contentIFrame中?

Image loaded when opening page for associated view 打开关联视图的页面时加载的图像

When implementing 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. 实际上,Dynamics正在添加一个带有ms-crm-Grid-DataColumn-ImgItem类的div。 This div contains an img element, sometimes with a src and most of the times with no src at all, example here . 这个div包含一个img元素,有时带有src,并且大多数时候根本没有src, 例如此处

I have developed a work-around for this that's working for Dynamics 365, but very unsupported by Microsoft. 我已经为此开发了一种变通方法,该变通方法适用于Dynamics 365,但Microsoft完全不支持。 Please visit this page and vote this issue up so we can get a supported solution. 请访问此页面并投票解决此问题,以便我们获得受支持的解决方案。

//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;
}

This blog states subgrid icons displaying sporadically. 该博客规定了子网格图标偶尔显示。 Clicking 'Refresh list' from context menu solves the issue sometimes. 从上下文菜单中单击“刷新列表”有时可以解决该问题。 Still it's not 100% fruitful. 仍然不是100%富有成果的。

As a supported workaround, you can show the Associated view with icons in IFRAME like discussed here . 作为一个支持的替代方法,可以显示与图标IFRAME喜欢讨论的相关视图这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM