cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member

Part 1: Preparation And Setup

  1. Download the BloX Template Here
  2. Import the Template into BloX (tutorial here)
  3. Create an action called "Dim Swapper With Selection"
  4. Add the code below to the action and save it.
if(payload.data.selectVal != 0){
    // for selections that don't clear the columns
    var dimIndex = payload.data.selectVal - 1;
    var dimToSwapTo = payload.widget.metadata.panels[0].items[dimIndex];
    var widgetIds = payload.data.widgetToModify;
    var colToSwapIndex = payload.data.colToSwap - 1;
    payload.widget.dashboard.widgets.$$widgets
        .filter(i=>widgetIds.includes(i.oid))
        .forEach(function(widget){
            widget.metadata.panels[0].items[colToSwapIndex] = dimToSwapTo;
            widget.changesMade();
            widget.refresh();
            })
} else {
    // for selections that do clear the columns
    var colToSwap = payload.data.colToSwap;
    var widgetIds = payload.data.widgetToModify;
    payload.widget.dashboard.widgets.$$widgets
        .filter(i=>widgetIds.includes(i.oid))
        .forEach(function(widget){
            widget.metadata.panels[0].items.length = colToSwap-1;
            widget.changesMade();
            widget.refresh();
            })
}

Part 2: Configuration

IMPORTANT POINTS:

  • One BloX Row Dimension Changer Widget corresponds to a single row item (Dimension).
  • This BloX can affect widgets other than pivots, however, more than TWO dimensions may cause the widgets to behave unexpectedly.
  • A button must exist for every dimension.

CONFIGURATION STEP A: DEFINING DIMENSIONS

Add the dimensions you want to be listed in the drop-down into the Items panel.
ORDER MATTERS

CONFIGURATION STEP B: REFERENCING DIMENSIONS IN THE EDITOR

In the Choice Set object edit the choices available to correspond to the dimensions in your Items panel.
  • The title argument is arbitrary. This means I can call my dimension whatever I want. If you added the items in the correct order, simply add titles of the dimensions in the items panel in their current order.
  • The value argument determines which dimension is selected from the items panel. If you added the items in the correct order, simply increment the value starting from 1 like in the example below:
For the example in the gif items panel above, we would use:
"choices": [
  {
   "title": "Date",
   "value": "1"
  },
  {
   "title": "Category",
   "value": "2"
  },
  {
   "title": "Condition",
   "value": "3"
  },
  {
   "title": "Age Range",
   "value": "4"
  }
]

[OPTIONAL] STEP B2: ADDING A "CLEAR SUBROWS FROM HERE" OPTION

You can add an additional option to your Row-Swapper Widget drop-down called Clear Subrows from Here. With this option, you can clear items from your pivot.
Clear Subrows from Here removes the level of aggregation at and from the current position. So, when selected on one Row-Swapper widget, you'll clear both that item and any more granular grouping categories from your Pivot.
For example, say I have 3 row-swapper widgets corresponding to a pivot that shows Date Age ➤ Condition. I want to clear Age and Condition. Selecting Clear Subrows from Here on the item Age (Row-Swapper Widget in the second position) would clear both Age and Condition from my pivot. Condition is a more granular level of analysis than Age. So, both items clear when you select Clear Subrows from Here on the column Age.
To add this option simply add another option into your ChoiceSet object.
{
   "title": "➡️ clear subrows from here",
   "value": "0"
}
The title is arbitrary. By default it is X-> clear subrows from here.
The value must be set to 0!

STEP C: CONFIGURING YOUR ACTION

The action has this format:
{

  "type": "Dim Swapper With Selection",
  "title": "swap dim",
  "data": {
     "widgetToModify": [
         "your Widget ID",
         "another Widget ID"
      ],
      "colToSwap": "1"
   }
}
You must configure the target widgets to modify and which column this action will affect.

CONFIGURING WIDGETSTOMODIFY

To get the ID of the widget you want to modify, open the widget editor and copy the ID after the /widgets/ in the URL.
Add this ID into the list (brackets) of widgetToModify.

CONFIGURING COLTOSWAP

Set which column you want this widget to affect. For example, if I want to modify column one, I would set colToSwap to 1. If I want to modify column 2, I would set it to column 2.
This part makes it easy to duplicate the widget and simply modify this argument to select different parts of the pivot table.
Apply and enjoy!
Comments
rhajlaoui
7 - Data Storage
7 - Data Storage

Hello,

I used the following script and it worked fine until we made an upgrade to Sisense 2023.1 😞

The new row is only added when I click on 'edit mode'.

 

wizsoft
8 - Cloud Apps
8 - Cloud Apps

hi,

it is not working for me too.

any help?

ILLIA
Sisense Team Member
Sisense Team Member

Greetings.
@wizsoft @rhajlaoui 

Due to changesMade method update, kindly ask you to change action code added in Part 1 to the following:

if (payload.data.selectVal != 0) {
    // for selections that don't clear the columns
    var dimIndex = payload.data.selectVal - 1;
    var dimToSwapTo = payload.widget.metadata.panels[0].items[dimIndex];
    var widgetIds = payload.data.widgetToModify;
    var colToSwapIndex = payload.data.colToSwap - 1;
    payload.widget.dashboard.widgets.$$widgets
        .filter(i => widgetIds.includes(i.oid))
        .forEach(function (widget) {
            widget.metadata.panels[0].items[colToSwapIndex] = dimToSwapTo;
            widget.changesMade('BloX', ['metadata']);
            widget.refresh();
        })
} else {
    // for selections that do clear the columns
    var colToSwap = payload.data.colToSwap;
    var widgetIds = payload.data.widgetToModify;
    payload.widget.dashboard.widgets.$$widgets
        .filter(i => widgetIds.includes(i.oid))
        .forEach(function (widget) {
            widget.metadata.panels[0].items.length = colToSwap - 1;
            widget.changesMade('BloX', ['metadata']);
            widget.refresh();
        })
}

 Kindly ask you to inform on the result.

Best regards,
Illia

dovg
7 - Data Storage
7 - Data Storage

Hi  @ILLIA 
I changed the action code with your changes. it affects only the "clear sub rows ..." option
can you check why the first part (until the else) of the code does not work?

thank you
Dov

Version history
Last update:
‎02-20-2024 02:12 PM
Updated by:
Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Developers Group:

Product Feedback Forum:

Need additional support?:

Submit a Support Request

The Legal Stuff

Have a question about the Sisense Community?

Email [email protected]

Share this page: