我想不出另一種比JavaScript更真實的解決方案。有可能使用lag in the sql,但只能用它來確定行顏色應該改變的位置。你可以在一列的html表達式中使用該列的值,並將其放入一個類中,但仍需要用javascript對它進行迭代。所以使用javascript看起來不那麼花哨。
內聯CSS:
table.report-standard tr.normalRow td{
background-color: green;
}
table.report-standard tr.altRow td{
background-color: red;
}
這將覆蓋默認的風格,但你將需要調整這個您的要求。例如,行上的hover上的顏色變化。我更喜歡通過分配類來指導樣式,然後在css中定義規則,而不是通過javascript直接分配css(這會將其放置在樣式標籤中,唉)。
- 動態動作:更改行的顏色
- 刷新,區之後,產品報告
真正的行動:執行JavaScript代碼,火在頁面加載檢查
$('td[headers="PRODUCT"]', this.triggeringElement).each(function(){
var lCurrRow = $(this).closest('tr'),
lPrevRow = lCurrRow.prev(),
lPrevVal = lPrevRow.find('td[headers="PRODUCT"]').text();
console.log(lPrevVal + ' - ' + $(this).text());
//if value on previous row differs from the that on the current row
//then change the class
//if the value didnt change, then use the same class as the previous row
if (lPrevVal != $(this).text()){
if (lPrevRow.hasClass('normalRow')){
lCurrRow.addClass('altRow');
} else {
lCurrRow.addClass('normalRow');
};
} else {
if (lPrevRow.hasClass('normalRow')){
lCurrRow.addClass('normalRow');
} else {
lCurrRow.addClass('altRow');
};
};
})
檢查解決方案在apex.oracle.com上,我在那裏實施。
來源
2013-04-28 17:27:25
Tom