selectByKeys(dim: PP.Mb.DimSource, args: Object, callback: Function | PP.Delegate, errorCallback: Function | PP.Delegate);
dim. Dictionary.
args. Operation arguments. An object must contain the following fields: selId - selection moniker; keys - keysa of selected elements; selCommand - operation type, element of the PP.Mb.SelCommands enumeration; dmElRelative - dependent elements relative to the specified keys, element of the PP.Mb.DmElRelative enumeration; fireEvent - indicates if the DimSrv.SelectionChanged event is called, if the parameter is set to True, the event is called.
callback. Callback function.
errorCallback. Callback function on error.
The selectByKeys method selects elements by keys.
Executing the example requires an instance of the DimSrv class named dimService (see DimSrv constructor). Add a handler for dictionary element selection change event. Set selection for all child elements of the element with the YEARS:2000 key and get names of all selected elements:
// Add a handler for dictionary element selection change event dimService.SelectionChanged.add(function(sender, args) { console.log("Element selection is changed"); }); // Set selection for all child elements of the element with the YEARS:2000 key var args = { keys: ["YEARS:2000"], selCommand: PP.Mb.SelCommands.Select, dmElRelative: PP.Mb.DmElRelative.Children }; var elemsForUpdate = []; dimService.selectByKeys(dim, args); // Get names of all selected dimension elements var func = function(sender, args) { var res = JSON.parse(args.ResponseText); var elems = res.GetDimElementsResult.els.e; console.log("Names of selected elements:"); for (var i in elems) { console.log(elems[i].n); elemsForUpdate.push(elems[i].k); } } dimService.getAllSelectedEls(dim, func); // Refresh the elements, for which selection is set dimService.updateStateData(dim, {keys: elemsForUpdate});
As a result the console displays names of all selected elements:
Element selection is changed
Names of selected elements:
I quarter 2000
II quarter 2000
III quarter 2000
IV quarter 2000
Deselect all dimension elements and check if there are selected elements:
// Deselect all elements args = { dmSelectionArg: { elSelectOp: PP.Mb.SelCommands.Deselect, elRelative: PP.Mb.DmElRelative.All } }; dimService.execCommand(dim, args); // Check if there are selected elements var func2 = function(sender, args) { var res = JSON.parse(args.ResponseText); var elems = res.GetDimElementsResult.els; console.log(elems ? "Selected elements exist" : "No selected elements"); } dimService.getAllSelectedEls(dim, func2);
As a result the console displays the result of check for selected elements:
Element selection is changed
No selected elements
See also: