cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
Description
Creating a clickable link control over a filter from another widget is a very common requirement. The end user clicks on a specific record inside of a PIVOT table. Then, a separate widget is being filtered based on the user choice. 
Special thanks to Elliott Herz and Artem Yevtushenko for helping creating the script.
Example
When the end-user clicks on "Creative Preview", the "Item Preview" widget is being filtered based on the auto_id in the Items List.
1st Click - 
2nd Click -
Limitations
The creation of the visible link script works currently with PIVOT table only
Solution Steps
1. Create 2 Widgets and a dashboard filter- 
a. The controlling widget - PIVOT table
b. The controlled widget - BloX (works with every type of widget)
c. Dashboard filter that is based on the same field of the first column of the controlling PIVOT widget and can effect on the controlled widget.
The controlling widget - PIVOT table
- The first column should include a value that will be send to the dashboard filter
The controlled widget - BloX
- The controlled widget has to be affected by the created dashboard filter - Test its effect by changing the filter value.
- Copy to notepad the widget from the URL - 
The dashboard filter
Set the filter type to be a "Single Select" widget:
Modify the script in the edit page of the controlling PIVOT widget:

Replace
a. var dim = [TableName.dashboardfilterfieldname]
b. var iframeWidgetId = 'controlled widget id'
var dim = "[Sheet1.auto_id]";

widget.on('domready', function(se, ev) {
 /*** USER CONFIGURATION **/
 var columnToMakeUrls = 0; // set the column to make linkable (index starts at 0)
 var removeLinkDecoration = false; // remove the link underline
 var newText='Creative Preview'; // Replace the text in the column to be specifc text, leave blank to keep the original text
 var iframeWidgetId = '5c8fbdaa03aff6379426e2cb'; //replace with iframewidget oid
 
 var realColumnIndex = columnToMakeUrls + 1; //nth-child function is 1 based, make it zero for consistency with pivot version
 var cellsSelector = 'table tbody td:nth-child(' + realColumnIndex + ')';
 var cells = $(cellsSelector, element); //get all the cells of the column
 var pivots = $('dashboard widget.columnar');
 
  if (cells.length > 0) {
   cells.each(function() {
    createLinkHTML($(this));
   });
  } else {
   console.log('Cells were not found');
  }

 // create html link tag according to the cell and tag
 function createLinkHTML(cell) {
  var linkElement = $(cell);
  var link = linkElement.text();
  var linkText = newText || link;
  var htmlLink = '<a id="url" href="' + link + '" target="_blank">' + linkText + '</a>';
  //var htmlLink = '<t>' + newText + '</t>';
  if (removeLinkDecoration) {
   htmlLink = $(htmlLink).css('textDecoration', 'none').prop('outerHTML');
  }

  linkElement.html(htmlLink);
  linkElement.on('click', function(event) {
   event.preventDefault();
   // Find the iframe widget
   var matchingWidgets = prism.$ngscope.dashboard.widgets.$$widgets.filter(function(widget) {
    return widget.oid == iframeWidgetId;
   });

   // Only run if there was a match
   var iframeWidget = $$get(matchingWidgets, '0',null);

   if (iframeWidget) {
    iframeWidget.dashboard.filters.$$items.forEach((item) => {
     if(item.jaql.dim === dim) {
      item.jaql.filter.members[0] = $(this).attr("val");
      iframeWidget.dashboard.refresh(); 
     }
    });
   }
  });
 }
});
After saving the script and refreshing the PIVOT table widget edit page, the link should appear:

Save the widget (apply)
Check the functionality in the dashboard - click on the links and the controlled widget should react accordingly.
Version history
Last update:
‎03-02-2023 09:07 AM
Updated by:
Contributors
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: