Skip to Content
Technical Articles
Author's profile photo Sathyanarayanan S

Select All Option in Checkbox-Group (SAP Analytics Cloud, Analytic Application)

Hello Fellas,

One of the most required features in a checkbox is to select All and deselect All. Since the feature is not available in SAC, here is a workaround to implement the feature.

Step 1:

Create a Checkbox_Group1 with one value “All”

Create Checkbox_Group2 which will have the list of all items.

Step 2:

On Initialization, retrieve the list, add the members to checkbox and select all by default.

var list=Table_1.getDataSource().getMembers("State",5000); //List of members to be added to the checkbox
var j=0;
for(var i=0;i<list.length;i++)
	{
		if(list[i].id.length!==0) //To remove null values
			{
				Actual_list[j]=list[i].description;
				j++;
			}
	}
for(i=0;i<Actual_list.length;i++) // Add items to Checkbox
	{
		CheckboxGroup_2.addItem(Actual_list[i],Actual_list[i]);
	}
CheckboxGroup_2.setSelectedKeys(Actual_list); //Select all as default
Selected_list=Actual_list;
//Selected_list - Current selected list to apply filter etc
//Actual_list - Standard list to compare the selection

The below is how the checkbox will look during run time.

Step 3:

On Checkbox_Group1 onSelect check if All is checked or Unchecked and make changes in Checkbox_Group2 selection.

var selection=this.getSelectedTexts();
if(selection[0]==="All")
	{
		Selected_list=Actual_list;
                //Add Filter script
	}
else
	{
		Selected_list=[""];
                //Add Filter script
	}
CheckboxGroup_2.setSelectedKeys(Selected_list);

Step 4:

On Checkbox_Group2 on Select check the number of entries selected and compare with count of actual list, based on which change the Checkbox_Group1 selection.

var selection=this.getSelectedTexts();
if(selection.length===Actual_list.length)
	{
		CheckboxGroup_1.setSelectedKeys(["All"]);
                //Add Filter script
	}
else
	{
		CheckboxGroup_1.setSelectedKeys([""]);
                //Add Filter script
	}

Aaaand Voila!!

Now you can use select the “All” entry to Select All or Deselect All.

Using Buttons:

Alternatively you can add two Buttons to Do the actions, which uses much simpler scripting.

The application will look like below in run time.

//Select All
CheckboxGroup_2.setSelectedKeys(Selected_list);
//Add Filter script

//De-Select All
CheckboxGroup_2.setSelectedKeys([]);
//Add Filter script

The above variants can be used with an input field to create similar to Dimension Filter in SAP Lumira… But that’s for another time… Thank you guys for your time meet Y’all in the next post..

 

-Sathya

Assigned Tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Tom Leppens
      Tom Leppens

      This example will not allways work as expected.
      Imagine that your user first selects a second item from the list (for example "Kenya"), after this he tries to change his selection to "ALL".

      if(selection[0]==="All")

      will return false as selection [0] = "Kenya";
      selection[1] = "All";

      Better would be to loop trough all selection-items to match with All, instead of just checking the first one.

      Author's profile photo Sathyanarayanan S
      Sathyanarayanan S
      Blog Post Author

      The "All" field is in checkbox group 1 which is the only value, whereas the the value "Kenya"  is in checkbox group 2.

      The part you mention is on Checkboxgroup 1 which will either have the value "All" or Null.

      Hence this will work. i have also tested this and is a working in once of our live application.

      Author's profile photo Semra Mancolgu
      Semra Mancolgu

      hi,

      how is declared ‘actual_list’?

       

      Author's profile photo Anita Dhale
      Anita Dhale

      yes didnt find where is it defined

      Author's profile photo Stephen Kanakaraj
      Stephen Kanakaraj

      One of the way you can create an array is:

      var actual_list = [" "];

      actual_list.pop;

       

      Author's profile photo Anita Dhale
      Anita Dhale

      code is not working for me. checkbox group 2 is not at all populated with values.