Search code examples
javascriptoracle-apex

How to dynamically select Interactive Grid rows by column value


I currently want to be able to dynamically select rows of an interactive grid by passing csv of column values to a JS-code dynamic action. Here is the code I have so far

var columnName = 'CRITERIA_ID';
var targetValues = $v("P13_SELECTED_VALUES").split(";");
//P13_SELECTED_VALUES is set to 112:113:115 via a static assignment DA that occurs directly before this 
console.log(targetValues[1]);
console.log(targetValues[2]);
console.log(targetValues[3]);

var ig$ = apex.region("myIG_StaticID").widget();
var view = ig$.interactiveGrid("getCurrentView");

view.model.forEach(function(record) {
  var columnValue = view.model.getValue(columnName, record);
  console.log("Column Value: " + columnValue);

  if (targetValues.includes(columnValue)) {
    view.grid.selection.add(record);
  }
});

When this is ran I don't get any errors in the console, but no selections occur. The console.log lines that I added do get triggered but in every single case, instead of outputing the variables, they output 'undefined'. This includes for the values of the targetValues array and the output of columnValue within the loop later on.

Any help would be greatly appreciated, even if it gets me to output the values I am attempting to check with my console.log commands.


Solution

  • I think you are close - what I can see you would need 2 minor changes:

    1. Start index with zero:

      console.log(targetValues[0]); console.log(targetValues[1]); console.log(targetValues[2]);

    2. pass record first:

      var columnValue = view.model.getValue(record, columnName);

    Edit: one more:

    let recordSelection = [];
    view.model.forEach(function(record) {
      var columnValue = view.model.getValue(record, columnName);
      console.log("Column Value: " + columnValue);
    
      if (targetValues.includes(columnValue)) {
        recordSelection.push(record);
      }
    });
    view.setSelectedRecords(recordSelection);