Skip to content

Instantly share code, notes, and snippets.

@jon-dixon
Last active December 4, 2022 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jon-dixon/faa1325a8b41b35f939e830291416955 to your computer and use it in GitHub Desktop.
Save jon-dixon/faa1325a8b41b35f939e830291416955 to your computer and use it in GitHub Desktop.
APEX Interactive Grid JavaScript Utilities
/**
* @namespace var igUtil = {};
**/
var igUtil = {};
/**
* @function selectedPKs
* @example igUtil.selectedPKs("customers", "P10_CUSTOMER_IDS", "Please select at least one customer");
**/
igUtil.selectedPKs = function (IGStaticId, returnPageItem, minSelectionMsg) {
// Get the Interactive Grid View
var gridView = apex.region(IGStaticId).widget().interactiveGrid("getViews").grid;
// Get the currently seledcted/checked records from the IG view
var records = gridView.getSelectedRecords();
// Create Array of Primary Key Values (getRecordId) from the selected records
var ids = records.map(function(r) { return gridView.model.getRecordId(r); } );
// Populate APEX Page Item with the selected IDs delimited with a ':'
apex.item(returnPageItem).setValue( ids.join(":") );
// Log Debug Messages.
apex.debug.info("IG Region Static ID: " + IGStaticId);
apex.debug.info("Return Page Item: " + returnPageItem);
apex.debug.info("Count Selected IDs: " + ids.length);
apex.debug.info("Selected IDs: " + ids.join(":"));
// If minSelectionMsg is populated then user must select at least one item.
if (ids.length === 0 && minSelectionMsg) {
// User did not select at least 1 record, so show the error message and return false.
apex.message.clearErrors();
apex.message.showErrors([
{type: "error",
location: "page",
message: minSelectionMsg,
unsafe: false}]);
return false;
} else {
// All good.
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment