如何在添加新的attributeModifier时删除以前的attributeModifier?
问题描述:
我有两列是orderbyborder链接。当我点击一列时,我通过以下方式添加attributeModifier来更改列的颜色:如何在添加新的attributeModifier时删除以前的attributeModifier?
add(new AttributeModifier("style", true, new Model<String>("background-color:#80b6ed;")));
这工作正常。但是当我点击第二列时,第一列仍然是已更改的颜色。但我希望只有我点击的列应该拥有这个属性修改器!
答
你不应该改变修饰符。
诀窍是让你的模型返回正确的值。因此,而不是使用new Model<String>("background-color:#80b6ed;")
,它总是返回相同的恒定值,你会碰到这样的:
new Model<String>() {
@Override
public String getObject() {
if(columnName.equals(selectedColumn) { //or something along these lines, to check if the current column is the selected one
return "background-color:#80b6ed;";
}
return "background-color:white;";
}
}
当然,这也意味着当你创建它们,不要,你可以添加属性修改每列”之后不必担心。
答
另一种方法来实现你想要的是通过Javascript添加一个css类到选定的行(从旧的删除类)。
Thnx很多...我有这个想法来实现..bt你的答案给了我实现的方式.... thnx再次... – Samrat 2011-06-13 06:35:17