Oracle Apex Interactive Grid Record Selection not persistent upon search and select

340 views Asked by At

I have an interactive grid where i select the records and add to another table. This interactive grid has many rows spawned over multiple pages. When i select the records by navigating through multiple pages the selected records are persistent, but when i try to search for a record the selected records are erased and only the new one which is searched is shown.

I have put this below code in the IG attributes Javascript section.

function(options) {
  options.defaultGridViewOptions = {
    persistSelection: true
  };
  return options;
}

This is not making the selection persistent when data is searched and selected. Any suggestions would be really helpful.

Thank you

1

There are 1 answers

5
Koen Lostrie On

Persisent selection preserves selection when navigating to other pages. When a search is performed, the selection is reset. That is the behaviour you're seeing. A workaround is to store the selected items in a page item and add to it. Here is an example on an interactive grid on the EMP table:

  • Create a page item to hold the selected values P184_SELECTED_EMP
  • Create a dynamic action on "Selection Change [Interactive Grid]" with the following javascript code:
function removeDuplicates(arr) {
    return arr.filter((item,
        index) => arr.indexOf(item) === index);
}

const model = this.data.model,
    records = this.data.selectedRecords;
let selectedvalues = records.map( r => model.getValue( r, "ENAME" ) ); // replace NAME with the desired column
//store old values in an array, filter out empty elements
let oldvalues = $v("P184_SELECTED_EMP").split(':').filter(Boolean);
let allvalues = removeDuplicates(oldvalues.concat(selectedvalues));
// now do something with values...
// put them in an item as a : delimited string
$s( "P184_SELECTED_EMP", allvalues.join(":") );

Note that it is not possible to "unselect" something with the code above, because it is impossible to know if something was selected before a search or not.