Changing fields on dynamic oracle apex report

2019-06-08 18:18发布

Nor newbie and nor advanced apex user here,
But,
I'm very naive on major client side web languages, and now I need to face it. And soon.
I have an example here - user : test and password test. I'm based on the very same jquery and javascript function from here, answered by Mr. Tony Andrews. At my app example, when the priority field is changed it puts in the value of A field, when its not 0, nor null . Its simply multiply the result in that field.
I'm trying to put a change priority script from priority field when its change. For example: When would change the priority of id=1, to 1, the priority from id=2 must be changed to 3 - the original priority from id=1.
I know it's a very basic algorithm, but I don't know how to do it just in time, on javascript or jQuery calls on apex. I'm been trying to more complex manipulations on report, but I need to understand the basics first.

For clarification my query report and javascript execution is:

select distinct
apex_item.checkbox2(10,r.ID) ID,
apex_item.text(11,r.ID) ID_2,
apex_item.text(20,r.PRIORIDADE) PRIORITY,
apex_item.text(30,1) a,
apex_item.SELECT_LIST_FROM_LOV(31,r.PRIORIDADE,'LISTAPRIORIDADES',NULL,'NO') PRIORITY_LOV, 
apex_item.text(40,null) b,


(select seq_id from apex_collections c  where collection_name = 'COLECAO'  AND c001 = r.id
)sequencial
from REPRIORIZA r



order by id;    
     //javascript execution, on dynamic action:

    var target = apex.jQuery(this.triggeringElement).closest('tr').find('input[name="f30"]')
    console.log(target)
    var source = apex.jQuery(this.triggeringElement).closest('tr').find('input[name="f20"]')
    console.log(source)
    var result = target.val() * source.val();
    target.val(result);
    console.log(target)

        var target2 = apex.jQuery(this.triggeringElement).closest('tr').find('input[name="f40"]')
        console.log(target)
        var source2 = apex.jQuery(this.triggeringElement).closest('tr').find('input[name="f11"]')
        console.log(source2)
        var result2 = source2.val();
        target2.val(result2);

Regards,

2条回答
2楼-- · 2019-06-08 18:24

There are a few ways to do this, my suggestion is as follows:

1 - Use the attributes 'p_attributes' and 'p_item-id' in your select when do you write apex_item code, like this:

https://docs.oracle.com/cd/E14373_01/apirefs.32/e13369/apex_item.htm#AEAPI211

https://docs.oracle.com/cd/E14373_01/apirefs.32/e13369/apex_item.htm#AEAPI206

apex_item.text(
    p_idx  => 20,
    p_value => 1,
    p_attributes  => 'data-id="' || CUSTOMER_ID || '"',
    p_item_id => 'priority' || CUSTOMER_ID) 
priority,
apex_item.text(
    p_idx => 30,
    p_value => 1,
    p_attributes  => 'data-id="' || CUSTOMER_ID || '"',
    p_item_id => 'a' || CUSTOMER_ID) 
a,
apex_item.SELECT_LIST_FROM_LOV(
    p_idx => 31,
    p_value  => 1,
    p_lov  => 'LISTAPRIORIDADES',
    p_attributes  => 'data-id="' || CUSTOMER_ID || '"',
    p_show_null => 'NO',
    p_item_id => 'lov' || CUSTOMER_ID)
PRIORITY_LOV

When you do this, you can access every item from the same line easily. These select is from a example table in my workspace, adapt these data to your table.

2 - Create a dynamic action to trigger when change the lov, this dynamic action should execute a javascript code.

enter image description here

3 - In your javascript code of this DA you can get every element of the line with this code:

var lineId = this.triggeringElement.getAttribute('data-id');
var lovItem = document.getElementById('lov' + lineId);
var aItem = document.getElementById('a' + lineId);
var priorityItem = document.getElementById('priority' + lineId);

enter image description here

Now you can do everything with lovItem, aItem and priorityItem fields.

4 - in your example page, the id column are sequential, so you can get the next line just incrementing the lineId variable like this:

var nextLineId = lineId + 1;
var nextLovItem = document.getElementById('lov' + nextLineId);
var nextAItem = document.getElementById('a' + nextLineId);
var nextPriorityItem = document.getElementById('priority' + nextLineId);

*If the values are not sequential, maybe you can create one more attribute in your apex_item on the "p_attributes" parameter using lead or lag function. https://oracle-base.com/articles/misc/lag-lead-analytic-functions

查看更多
The star\"
3楼-- · 2019-06-08 18:28

Well,

For the case what I asked a possible answer is :

var target = apex.jQuery(this.triggeringElement).closest('tr').find('input[name="f30"]')
//console.log(target)
var source = apex.jQuery(this.triggeringElement).find('input[name="f20"]')

console.log(source)
console.log('valor default: '.concat(source.context.defaultValue))
//var lista  =  apex.jQuery(this.affectedElements[0].innerHTML).find('input[name="f20"]')
var lista  =  apex.jQuery(source.context.form).find('input[name="f20"]')
console.log('lista: '.concat(lista))
for (var x=0;x<lista.length;x++){
    if (source.context.value == lista[x].value && source.context.defaultValue != lista[x].defaultValue){
        console.log(source)
        lista[x].value = source.context.defaultValue
        lista[x].defaultValue = source.context.defaultValue
        source.context.defaultValue = source.context.value
        console.log(lista[x])
    }
}
var colecao = apex.jQuery().find('input[name="f20"]')

var result = target.val() * source.val();

This code will change the value between one existing in another row. Tks for previous contributions!

查看更多
登录 后发表回答