返回颜色代码的计算列 [英] Calculated Columns that Return Color Code

查看:78
本文介绍了返回颜色代码的计算列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好 -

我的用户具有独特的业务逻辑,需要根据计算显示颜色代码

I have user who has unique business logic and need to display color code based on calculation

以下是业务规则:

如果状态列(百分比)小于状态日期(日期选择器列)之前的40%和50个工作日,则SharePoint将返回黄色代码

If Status Column (Percentage) is less that 40% and 50 weekdays before Status Date (Date picker column) then SharePoint returns Yellow color code

如果状态列(百分比)小于状态日期(日期选择器列)之前的80%和80个工作日,则SharePoint返回红色代码

If Status Column (Percentage) is less that 80% and 80 weekdays before Status Date (Date picker column) then SharePoint returns red color code

任何想法如何解决这个?

Any ideas how to resolve this?

推荐答案

我们可以使用JSLink来实现它。将下面的代码添加到列表视图页面的脚本编辑器Web部件中。

We can use JSLink to achieve it. Add the code below into script editor web part in the list view page.

在下面的代码中,我只根据PercentComplete字段突出显示row 。我建议您提供有关其他 字段"状态日期"的更多信息。你对"状态日期前50个工作日"的意思是什么? "50个工作日"和"50个工作日"。
是指50个工作日? "状态日期"是指"截止日期"?

In my code below, I only highlight row base on PercentComplete field. I suggest you provide more information about another field "Status Date". What do you mean about the "50 weekdays before Status Date"? The "50 weekdays" mean 50 working days? The "Status Date" mean "Due Date"?

<script type="text/javascript">
(function() {
	var overrideCurrentContext = {};
	overrideCurrentContext.Templates = {};
	overrideCurrentContext.OnPostRender = HighlightRows;
	SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);
})();

function HighlightRows(ctx) {	
	var rows = ctx.ListData.Row;
	for (var i = 0; i < rows.length; i++) {
		var pComplete = rows[i]["PercentComplete"];
		pComplete =pComplete.split(' %')[0];
		var rowId = GenerateIIDForListItem(ctx, rows[i]);
		var row = document.getElementById(rowId);
		
		if(pComplete<=40){
			row.style.backgroundColor = "Yellow";
		}
		if(pComplete>40&&pComplete<=80){
			row.style.backgroundColor = "Red";
		}		
	}
}
</script>

更多信息:

https://nearbaseline.com/2013/12/sharepoint-list-conditional-formatting-with-jslink/

https://code.msdn.microsoft .com / office / Client-side-rendering-code-0a786cdd

最诚挚的问候,

丹尼斯


这篇关于返回颜色代码的计算列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆