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

编辑

我注意到,如果在转到子网格所在的页面之前打开用于关联视图的页面,则该图标会出现在子网格中。

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

Image loaded when opening page for associated view

最佳答案

实施this solution时,刷新子网格后会偶尔出现子网格图标。实际上,Dynamics正在添加一个带有ms-crm-Grid-DataColumn-ImgItem类的div。该div包含一个img元素,有时带有src,大多数时候根本没有src,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;
}

关于javascript - 是否可以在CRM的子网格中添加图标?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45755618/

10-12 18:19