[英]How to apply Javascript to a grouped SharePoint list?
I am fairly new to the SharePoint customization scene but have picked up some javascript which will change the background colour of a cell in a SP list dependent on the value of the cell. 我是相当新的SharePoint自定义场景,但是拿起一些JavaScript代码,这将改变一个单元格的背景颜色依赖于细胞的值的SP名单。
This works fine on normal views but anything that is grouped doesn't work which i beleive is something to do with the order the page loads. 这在普通视图上工作正常,但是任何分组的操作都不起作用,我相信这与页面加载的顺序有关。 Is there a way to apply javascript to a view that is grouped and set to collapsed as default?
有没有一种方法可以将javascript应用于已分组并默认设置为折叠的视图?
I have seen another thread from last year with a similar query but there doesn't appear to be a resolution to it. 我从去年看到了另一个具有类似查询的主题,但似乎没有解决的方法。
Many Thanks in Advance!!! 提前谢谢了!!!
Dan 担
This is the code that im using for the cell colour change: 这是即时消息用于单元格颜色更改的代码:
<script type="text/javascript" language="javascript">
var x = document.getElementsByTagName("TD") // find all of the TDs
var i=0;
for (i=0;i<x.length;i++)
{
if (x[i].className=="ms-vb2") //find the TDs styled for lists
{
if (x[i].innerHTML=="Green" && x[i].cellIndex==10)
{
x[i].style.backgroundColor='forestgreen'; // set the background color
x[i].style.color='Black'; //set the font color
}
if (x[i].innerHTML=="Amber" && x[i].cellIndex==10)
{
x[i].style.backgroundColor='Goldenrod'; // set the background color
x[i].style.color='Black'; //set the font color
}
if (x[i].innerHTML=="Red" && x[i].cellIndex==10)
{
x[i].style.backgroundColor='Firebrick'; // set the background color
x[i].style.color='black'; //set the font color
}
}
}
</script>
Maybe in your case it would be much easier to customize the CSS style for the given column. 也许就您而言,为给定的列自定义CSS样式会容易得多。 You can define a new CSS rule extending the ms-vb2 class but only applies to 10th column.
您可以定义新的CSS规则来扩展ms-vb2类,但仅适用于第10列。 Use a CSS selector can easily achieve this.
使用CSS选择器可以轻松实现这一目标。
For instance, locate the CSS style sheet with applies to this cell, and define a new rule: .ms-vb2:nth-child(10)[innelHtml='Red']{ Background-color:firebrick; 例如,找到适用于此单元格的CSS样式表,然后定义一个新规则:.ms-vb2:nth-child(10)[innelHtml ='Red'] {Background-color:firebrick; Color:black }
颜色:黑色}
Then whenever your table cell is visible, the CSS will apply. 然后,只要表格单元格可见,就会应用CSS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.