這個例子實現的是商機的商機階段(statuscode)字段值若是是量產,整行記錄換個顏色。javascript
將要修改的實體,我這裏是商機實體,加入一個解決方案,而後導出這個解決方案,解壓,而後修改其中的 customizations.xml ,將RibbonDiffXml 這個元素之間的值替換爲以下:css
<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資源,編輯其文本,在最後增長一句話:java
function load() {var x = 1;}web
上傳名爲 /Scripts/ColorScripts.js 的web資源,代碼是,下面紅色代碼statuscode要換成你要判斷的字段的邏輯名字。this
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); } }
發佈後就能夠看到效果了。spa