[英]Show/hide column in rich:extendedDataTable (RichFaces 4.x)
RichFaces' show/hide column feature for rich:extendedDataTable
is not available any more for the version 4.x. RichFaces针对
rich:extendedDataTable
的显示/隐藏列功能在版本4.x中不再可用。 Any ideas how to implement it in some other way? 有什么想法如何以其他方式实现它吗?
I tried to do it using JavaScript, with the document.getElementById()
function and setting the element's style.display
property, but it is hard to locate an element by id since all elements in rich:table
are generated dynamically. 我尝试使用JavaScript和
document.getElementById()
函数并设置元素的style.display
属性来实现此目的,但是由于id rich:table
中的所有元素都是动态生成的,因此很难通过id来查找元素。
Any help and hints will be appreciated. 任何帮助和提示将不胜感激。
In Richfaces 4.x extendedDataTable, you could use css style to control both the header and body of that column in the same time. 在Richfaces 4.x ExtendedDataTable中,您可以使用CSS样式同时控制该列的标题和正文。 The css style of each column is created with the prefix ".rf-edt-c-" and column id.
每列的CSS样式均以前缀“ .rf-edt-c-”和列ID创建。 If you have a column with id "column1", the css style will be ".rf-edt-c-column1".
如果您的ID为“ column1”的列,则CSS样式将为“ .rf-edt-c-column1”。 The following is an example to hide/show the column with column id in Java Script.
以下是在Java Script中隐藏/显示具有列ID的列的示例。
<script type="text/javascript">
//<![CDATA[
function hideColumn(columnId)
{
var styleSheets = document.styleSheets;
for(var i=0;i<styleSheets.length;i++)
{
var rules = null;
// IE and Chrome
if(styleSheets[i].rules != null)
{
rules = styleSheets[i].rules;
}
// Firefox
else if(styleSheets[i].cssRules != null)
{
rules = styleSheets[i].cssRules;
}
for(var j=0;j<rules.length;j++)
{
// Find the css style of that column
if(rules[j].selectorText==".rf-edt-c-" + columnId)
{
rules[j].style.display = "none";
}
}
}
}
function showColumn(columnId)
{
var styleSheets = document.styleSheets;
for(var i=0;i<styleSheets.length;i++)
{
var rules = null;
// IE and Chrome
if(styleSheets[i].rules != null)
{
rules = styleSheets[i].rules;
}
// Firefox
else if(styleSheets[i].cssRules != null)
{
rules = styleSheets[i].cssRules;
}
for(var j=0;j<rules.length;j++)
{
// Find the css style of that column
if(rules[j].selectorText==".rf-edt-c-" + columnId)
{
rules[j].style.display = "";
}
}
}
}
//]]>
</script>
Just put the attribute visible="false"
in the rich:column
tag like this: 只需将属性
visible="false"
放在the rich:column
标记中,如下所示:
<rich:column id="name" label="Name" sortable="true" sortBy="#{edt.name}" visible="false">
Wrong RichFaces version, sorry. RichFaces版本错误,抱歉。
I add this in rich:column
attributes: 我将此添加到
rich:column
属性中:
width="#{myBean.testDisplay('toDisplay')?'':'0px;border:none;'}"
It is better than using rendered
because rendered
bugs with the columns rearrangement. 它比使用
rendered
更好,因为rendered
错误会重新排列列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.