Oracle APEX:为表格形式的列中的值着色
Oracle APEX: Color the values in column of tabular form
我有一个 tabular form
,我想用不同的颜色显示列 delta 的值。 Delta 是 column1 和 column2 之间的差异,这是我动态生成的。
如果 delta 值为 >0
,则颜色不变,如果 delta 为 <0
,则该值应为红色,如果值为 0
,则为绿色。
我正在使用 Oracle APEX 版本:4.2.1
我前段时间遇到过类似的问题,我的做法是:
先声明一个cssclass
.cellColored{background-color:#ff0000 !important}
/*notice the !important attribute, if not declared the browser will use the apex css definition*/
然后转到您的表格形式定义 -> 区域定义 -> 属性
在静态 ID 中添加和 id 如下:
tab_form_id
然后转到表格表单定义中的报告属性并编辑要绘制的列,在字段 'Element Attributes' 中添加:class='classDelta'
然后 运行 javascript 函数将 cellColored class 分配给符合条件的 table 单元格,如下所示:
function paintCells(){
var tabForm = document.getElementById('tab_form_id');
var cells = tabForm.getElementsByTagName('td');
for(var i = 0; i < cells.length; i++){
if((cells[i].headers === 'DELTA') && (Number(cells[i].getElementsByClassName('classDelta')[0].value) < 0)){
cells[i].className = cells[i].className + ' cellColored';
}
}
}
注意 cells[i].headers === 'DELTA'
行,这应该是报告中定义的列的名称。
编辑
上面是输入类型的元素,对于只读列你需要使用这个函数:
function paintCells(){
var tabForm = document.getElementById('tab_form_id');
var cells = tabForm.getElementsByTagName('td');
for(var i = 0; i < cells.length; i++){
if((cells[i].headers === 'DELTA') && (Number(cells[i].innerHTML) < 0)){
cells[i].className = cells[i].className + ' cellColored';
}
}
}
我有一个 tabular form
,我想用不同的颜色显示列 delta 的值。 Delta 是 column1 和 column2 之间的差异,这是我动态生成的。
如果 delta 值为 >0
,则颜色不变,如果 delta 为 <0
,则该值应为红色,如果值为 0
,则为绿色。
我正在使用 Oracle APEX 版本:4.2.1
我前段时间遇到过类似的问题,我的做法是:
先声明一个cssclass
.cellColored{background-color:#ff0000 !important}
/*notice the !important attribute, if not declared the browser will use the apex css definition*/
然后转到您的表格形式定义 -> 区域定义 -> 属性 在静态 ID 中添加和 id 如下:
tab_form_id
然后转到表格表单定义中的报告属性并编辑要绘制的列,在字段 'Element Attributes' 中添加:class='classDelta'
然后 运行 javascript 函数将 cellColored class 分配给符合条件的 table 单元格,如下所示:
function paintCells(){
var tabForm = document.getElementById('tab_form_id');
var cells = tabForm.getElementsByTagName('td');
for(var i = 0; i < cells.length; i++){
if((cells[i].headers === 'DELTA') && (Number(cells[i].getElementsByClassName('classDelta')[0].value) < 0)){
cells[i].className = cells[i].className + ' cellColored';
}
}
}
注意 cells[i].headers === 'DELTA'
行,这应该是报告中定义的列的名称。
编辑
上面是输入类型的元素,对于只读列你需要使用这个函数:
function paintCells(){
var tabForm = document.getElementById('tab_form_id');
var cells = tabForm.getElementsByTagName('td');
for(var i = 0; i < cells.length; i++){
if((cells[i].headers === 'DELTA') && (Number(cells[i].innerHTML) < 0)){
cells[i].className = cells[i].className + ' cellColored';
}
}
}