CRM 2011 视图根据某个字段变颜色

这个例子实现的是商机的商机阶段(statuscode)字段值如果是量产,整行记录换个颜色。

将要修改的实体,我这里是商机实体,加入一个解决方案,然后导出这个解决方案,解压,然后修改其中的 customizations.xml  ,将RibbonDiffXml 这个元素之间的值替换为如下:

<RibbonDiffXml>
    <CustomActions>
      <CustomAction 
        Id="McTools.HomePageGrid.opportunity.Colorization" 
        Location="Mscrm.HomepageGrid.opportunity.MainTab.Actions.Controls._children" 
        Sequence="10">
        <CommandUIDefinition>
          <Button 
            Command="ColorizeView.Command" 
            CommandType="General" 
            Id="McTools.HomePageGrid.opportunity.Colorization.Button" 
            Image32by32="/_imgs/Ribbon/Actions_32.png" 
            LabelText="条件格式" 
            Sequence="10" 
            TemplateAlias="o1" />
        </CommandUIDefinition>
      </CustomAction>
    </CustomActions>
    <Templates>
      <RibbonTemplates Id="Mscrm.Templates" />
    </Templates>
    <CommandDefinitions>
      <CommandDefinition Id="ColorizeView.Command">
        <EnableRules>
          <EnableRule Id="ColorizeRule" />
        </EnableRules>
        <DisplayRules />
        <Actions />
      </CommandDefinition>
    </CommandDefinitions>
    <RuleDefinitions>
      <TabDisplayRules />
      <DisplayRules>
        <DisplayRule Id="ColorizeView.Command.DisplayRule.SkuRule">
          <SkuRule Default="false" InvertResult="false" Sku="Online" />
        </DisplayRule>
      </DisplayRules>
      <EnableRules>
        <EnableRule Id="ColorizeRule">
          <CustomRule 
            Default="true" 
            InvertResult="false" 
            FunctionName="load" 
            Library="$webresource:hd_/Scripts/jQueryColor.js" />
          <CustomRule 
            Default="false" 
            InvertResult="false" 
            FunctionName="load" 
            Library="$webresource:hd_/Scripts/ColorScripts.js">
            <CrmParameter Value="SelectedControlAllItemReferences" />
            <CrmParameter Value="SelectedControl" />
          </CustomRule>
        </EnableRule>
      </EnableRules>
    </RuleDefinitions>
    <LocLabels />
</RibbonDiffXml>

上传一个名为 /Scripts/jQueryColor.js 的jscript类型的web资源,编辑其文本,在最后增加一句话:

function load() {var x = 1;}

上传名为 /Scripts/ColorScripts.js 的web资源,代码是,下面红色代码statuscode要换成你要判断的字段的逻辑名字。

function load(items, grid) {
    try {
        if (items) {
            var index = $("#gridBodyTable").find("col[name=statuscode]").index();
            if (index >= 0) {
                for (var i = 0; i < items.length; i++) {
                    var id = items[i].Id;

                    $(grid._element).find("tr[oid='" + id + "']").each(function () {
                        var theTr = $(this);

                        if (theTr.find("td:nth-child(" + (index / 1 + 1 / 1) + ")")[0].innerText.indexOf("量产") >= 0) {
                            theTr.find("td").css("background-color", "#d6fab6");
                        }
                    });
                }
            }
        }
    }
    catch (e) {
        alert(e.description);
    }
}

发布后就可以看到效果了。

原文地址:https://www.cnblogs.com/z1984/p/3161243.html