关闭对话框后保存 Oracle Apex Classic Report 中当前行的突出显示 window

Saving the highlighting of current row in Oracle Apex Classic Report after closing the dialog window

大家晚上好!

目前我正在使用 Oracle Apex(版本 4.2.6.00.03)中的一页。它由两份经典报告组成——第一份是 "master" 份,第二份包含前者的 "details" 份。还有几个用于执行 inserting/updating/deleting 数据操作的按钮。我的目的不仅是使操作有效,并且 "details" 报告在从 "master" 中选择行时刷新(我已经完成了这些任务),而且还设法保存报告的突出显示' 行甚至在执行操作后(不仅仅是刷新页面)。

现在我将解释我已经完成的工作。可以通过我放在每个报告页脚中的脚本来选择行(并同时突出显示它),它看起来像这样:

<script>
$(".t20data","#master_report").live("click",function(){
  chooseMST($(this).find("span.MASTER").attr("id"));
});
</script>

master_report是"master"报告区域的ID,MASTER代表跨度class,其中我将报告中的所有单元格都包装起来以保留行 ID 的值。函数chooseMST是这样的:

function chooseMST(docID){
  $.post('wwv_flow.show',
         {'p_request'      : 'APPLICATION_PROCESS=SET_MASTER',
          'p_flow_id'      : $v('pFLowId'),
          'p_flow_step_id' : $v('pFlowStepId'),
          'p_instance'     : $v('pInstance'),
          'x01'            : docID},
         function(data){
          //refreshes "details" report
          $('#detail_report').trigger('apexrefresh');
          //deletes color from all the rows of "master" report
          $(".t20data","#master_report").parent("tr").children().css("background-color","#F2F2F5");
          //highlights the chosen row in "master" report
          $("#" + String(docID)).parent("td").parent("tr").children().css("background-color","#A3BED8");
         }
        );
}

动作(比如,AJAX回调)SET_MASTER是这样的:

begin
  --clears the choice from "detail" report
  APEX_UTIL.SET_SESSION_STATE(P_NAME  => 'P400_DETAIL_RN'
                             ,P_VALUE => NULL);
  --makes the choice from "master" one
  APEX_UTIL.SET_SESSION_STATE(P_NAME  => 'P400_MASTER_RN'
                             ,P_VALUE => APEX_APPLICATION.G_X01);
end;

说一下刷新页面,我解决了清除隐藏项的问题P400_DETAIL_RNP400_MASTER_RN 通过使用此 PL/SQL 代码在 header 之前进行的过程:

begin
  :P400_DETAIL_RN := APEX_UTIL.GET_NUMERIC_SESSION_STATE(P_ITEM  => 'P400_DETAIL_RN');
  :P400_MASTER_RN := APEX_UTIL.GET_NUMERIC_SESSION_STATE(P_ITEM  => 'P400_MASTER_RN');
end;

和每次加载页面时执行的Javascript函数recolorRows

function recolorRows(){
  $(".t20data","#master_report").parent("tr").children().css("background-color","#F2F2F5");
  if($("P400_MASTER_RN").val() != "") $("#" + String($("P400_MASTER_RN").val())).parent("td").parent("tr").children().css("background-color","#A3BED8");
  $(".t20data","#detail_report").parent("tr").children().css("background-color","#F2F2F5");
  if($("P400_DETAIL_RN").val() != "") $("#" + String($("P400_DETAIL_RN").val())).parent("td").parent("tr").children().css("background-color","#A3BED8");
}

关于"details"报表行的代码是相似的,所以让我省略这部分。对我来说,问题是从执行操作数据的操作开始的。这是打开对话框 window 以插入或更新在 "master" 报告中选择的行的函数:

function MST_open(action){
  //the part of code which finds out with what parameteres we should call the dialog window
  $("#dialogFrame").attr("src",stringToCall);
  $("#dialogWindow").dialog({
    title:windowName,
    modal:true,
    width:500,
    height:500,
    resizable:true,
    close:reloadMST //the action on closing the window
  });
}

reloadMST的代码如下:

function reloadMST(){
  $("master_report").trigger('apexrefresh');
  $("detail_report").trigger('apexrefresh');
}

和 Javascript 函数,它在对话框 window 中执行特定按钮点击(例如,"Update"),是这样的:

function mstUpdate(){
  $.post('wwv_flow.show',
         {'p_request'      : 'APPLICATION_PROCESS=MASTER_UPDATE',
          'p_flow_id'      : $v('pFLowId'),
          'p_flow_step_id' : $v('pFlowStepId'),
          'p_instance'     : $v('pInstance'),
          'x01'            : apex.item("P402_SNAME").getValue()},
         function(data){
          //returns the ID of updated row in "msg" part of "res" variable
          var res = eval("(" + data + ")");
          if(res.status != "OK"){
            //the code which catches the error, if it appears
          } else {
            parent.MST_close(res.msg);
          }
         }
        );
}

其中MST_close是这样的:

function MST_close(docID){
  $("#dialogWindow").dialog("close");
  //see this function above
  chooseMST(docID);
}

因此,这是一个 Javascript 和 PL/SQL 操作链,涉及更新 "master" 报告中的行。 inserting/updating/deleting 数据的操作效果很好,但我不能对行颜色的保存说同样的话。后者在我只选择行或刷新页面时效果很好,但在执行更新后,当前行会失去其突出显示。通过调试(比如,在 Javascript 代码中添加函数 console.log)我发现必须导致保存突出显示的动作链名义上执行, 但看起来刷新报告要么 着色之后,要么只是阻止后者。

因此,我的问题是:有没有办法在打开和关闭 child 对话框后保存当前行的突出显示 window?

我认为问题在于,在模式 window 中更新记录的值后,您刷新了主页中 2 个报告中的数据,因此失去了突出显示。

要解决此问题,请尝试在区域的刷新事件上创建一个动态操作:您的经典报告 将执行 javascript 函数 recolorRows()。您也可以使用 javascript 来完成。主要思想是在刷新 2 个报告(使用 reloadMST() 或其他方法)后,您必须触发 recolorRows().

非常感谢,Cristian_I。我最近解决了我的问题。我的错误是我没有在 HTML 代码中绑定隐藏项 - 换句话说,仅通过 Javascript。观察隐藏项的行为,我发现当我试图在 jQuery 函数 $("#hidden_item").val() 的帮助下找到它们的值时,我得到了 previous 值,但不是 current 值(即会话状态值)。所以这就是为什么我的突出显示不稳定。

除了在刷新报告后立即触发动态操作外,我还应该在 "coloring" 代码本身之前将这些字符串添加到我的函数 chooseMST 中:

$("#P400_MASTER_RN").val(docID); //binding to exact string

$("#P400_DETAIL_RN").val(""); //clearing the choice in the "details" report.

因此,为行重新着色的问题就消失了!因此,现在我的页面运行良好:突出显示稳定,甚至新行在插入后立即突出显示。