1 Reply Latest reply on Sep 28, 2015 6:45 PM by diego.medrano

    Using JavaScript API to get formattedValue

    Alex Sulz

      Hi,

       

      I'm using the example from the tutorial on how to read formattedValue with JavaScript API call. It works as expected when clicked directly on the row.

       

      How to read the value clicking on first Region column?

       

      Get formattedValue.jpg

      function listenToMarksSelection() {

        viz.addEventListener(tableau.TableauEventName.MARKS_SELECTION, onMarksSelection);

      }

       

      function onMarksSelection(marksEvent) {

        return marksEvent.getMarksAsync().then(reportSelectedMarks);

      }

       

      function reportSelectedMarks(marks) {

        var html = [];

        for (var markIndex = 0; markIndex < marks.length; markIndex++) {

        var pairs = marks[markIndex].getPairs();

        html.push("<b>Mark " + markIndex + ":</b><ul>");

        for (var pairIndex = 0; pairIndex < pairs.length; pairIndex++) {

        var pair = pairs[pairIndex];

        html.push("<li><b>fieldName:</b> " + pair.fieldName);

        html.push("<br/><b>formattedValue:</b> " + pair.formattedValue + "</li>");

        }

        html.push("</ul>");

        }

       

      }

       

      Thank you