另一種解決方案:您可以使用JavaScript。對於我的DataTable,我想要着色列和焦點元素的行。 DataTable中包含了許多的inputText元素,如果它得到他們每個人的調用JavaScript函數的焦點:
<p:inputText id="xyz" ... onfocus="colorTR(#{data.id},1);" .../>
與JavaScript函數:
//colors row
function colorTR(row, cell){
var x = document.getElementsByTagName('tr');
var count = x.length;
for(var i=0; i!=count; ++i){
if(x[i].id[0] == 'p'){
if(i%2 == 0)
x[i].style.background = '#eeeeee';
else
x[i].style.background = '#fafafa';
var zahl = parseInt(x[i].id[x[i].id.length-2] + x[i].id[x[i].id.length-1]);
if(isNaN(zahl))
zahl = parseInt(x[i].id[x[i].id.length-1]);
if(zahl == row)
x[i].style.background = '#feac5b';
}
}
//colors column
x = document.getElementsByTagName('input');
count = x.length;
for(var i=0; i!=count; ++i){
if(x[i].id[0] == 'p'){
x[i].parentNode.style.background = 'transparent';
var zahl = parseInt(x[i].id[x[i].id.length-2] + x[i].id[x[i].id.length-1]);
if(isNaN(zahl))
zahl = parseInt(x[i].id[x[i].id.length-1]);
if(zahl == cell)
x[i].parentNode.style.background = '#feac5b';
}
}
//header column
x = document.getElementsByTagName('th');
count = x.length;
for(var i=0; i!=count; ++i){
if(x[i].id[0] == 'p'){
x[i].style.background = '#ffffff';
var zahl = parseInt(x[i].id[x[i].id.length-2] + x[i].id[x[i].id.length-1]);
if(isNaN(zahl))
zahl = parseInt(x[i].id[x[i].id.length-1]);
if(i == cell)
x[i].style.background = '#feac5b';
}
}
樣式datatable的哪一部分? – 2011-05-18 10:09:56
@Cagatay Civici標題和行(改變行的顏色,例如:白色,藍色,白色,藍色......) – Optimmus 2011-05-18 11:03:48
@Optimmus,你需要更具體一些,告訴我們你試圖去做什麼。 – 2011-05-18 11:05:31