What are the best ways to implement a dynamic matrix report using APEX?

Viewed 3575

I need to complete this task using Oracle Application Express framework.

Let's say we have such a query:

select   
  col1,  
  col2,  
  val1,  
  val2,  
  val3,  
  val4,  
  val5,  
  val6,  
  val7,  
  val8,  
  val9,  
  val10,  
  val11  
from table(mega_function(city => ?, format => ?, percent => ?, days => ?));

And this query returns something like this (shown in CSV format):

col1;col2;val1;val2;val3;val4;val5;val6;val7;val8;val9;val10;val11
S2;C1;32000;120;"15:38:28";1450;120;1500;1200;31000;120;32600;300
S1;C1;28700;120;"15:35:01";150;120;1500;1800;2700;60;28900;120
S1;C2;27000;240;"14:44:23";0;1500;240;1200;25500;60;null;null

To put it simple, the query bases on a pipelined function which takes some parameters and returns some set of values for different pairs of values of first two columns col1;col2.

What I need to implement is a matrix report where values of col1 are used as rows of the report and values of col2 as columns. On the intersection there are cells which contain set of values for the pair with some formatting and styles applied. What is also needed - is sorting by rows (which should sort columns by values of the column 'val1').

Or if we show the above needs on a mockup: mockup

So the question is - what are the best practises to implement such a matrix report with some interaction and custom styles?

What I have already tried to look into:

  • Interactive Report Pivot functionality (https://docs.oracle.com/cd/E71588_01/AEEUG/managing-pivot-reports.htm#AEEUG29137) - lacks customization, works badly with many values, especially when they are not numbers.
  • Classic report based on Function - I have implemented PL/SQL function which returns dynamic PIVOT SQL query, in the properties of the report Use Generic Column Names set to Yes (in order to parse the query only in runtime) and for headings of the report I used another PL/SQL function, which generates a string in the format heading1:headning2:...:headingN. The solution works (you can check it here - https://apex.oracle.com/pls/apex/f?p=132832:2), but I need to refresh the report dynamically every, let's say, 5 seconds, and it will suck in terms of performance (dynamic SQL is always bad and not managable way if we talk about execution plans). Also this solution doesn't fit, because headings are not concerted with the data (actually I used order by col1 in the queries in both PL/SQL functions to make headings be in their places) and I don't know how to make rows sortable here.
  • PL/SQL Dynamic Content Region - I haven't tried to code something here, but I realise that it's possible to do anything here just using HTP package and APEX API. The tricky thing is this solution is quite complex, I'll need to implement all the logic of the report 'from scratch' and I believe there's a better and easier way to succeed in the task, which I don't know.
3 Answers
Related