Link to home
Start Free TrialLog in
Avatar of Maliki Hassani
Maliki HassaniFlag for United States of America

asked on

Javascript: How to show value of a specific value

Hi Experts,

I am stuck on how to get the distinct value of a specific value in my array to be use as a label.  Looking to do something like this Distinct(pairs[1].formattedValue).  It will be added to the title of my excel file.  Report name: XXXX

Any ideas?


function getUnderlyingData(){
                sheet = viz.getWorkbook().getActiveSheet();
                sheet.selectMarksAsync( "Select All", 1,tableau.SelectionUpdateType.REPLACE).then( function() {
                    return sheet.getSelectedMarksAsync();
                    }).then(function(marks){
                    
                    /////////////////////// GET ARRAY OF VALUES
                    var vals = [];
                    //console.log(marks);
                    for(k=0;k<marks.length;k++){
                        pairs = marks[k].getPairs();
                        vals.push([pairs[1].formattedValue,pairs[2].formattedValue,pairs[3].formattedValue,pairs[4].formattedValue,pairs[5].formattedValue,pairs[6].formattedValue,pairs[7].formattedValue,pairs[8].formattedValue,pairs[9].formattedValue,pairs[10].formattedValue]);

                    }
                    
                    
                    /////////////////////// CREATE TABLE (Hidden) 


                    /////////////////////// Header in excel
                    var table = $('#header');
                    table.append($('<tbody>'));

                    $.each( vals, function( index, value ){
                        var row = $('<tr>');
                        $.each( vals[index], function(index2, value2) {
                            row.append($('<td>').text(value2));
                        });
                        table.append(row);

                    });

    
                    /////////////////////// EXPORT TO EXCEL

                    var data_type = 'data:application/vnd.ms-excel';
                    var table_div = document.getElementById('table_wrapper');
                    var table_html = table_div.outerHTML.replace(/ /g, '%20');
                    var a = document.createElement('a');

                    // APPEND TO DOCUMENT
                    document.body.appendChild(a);
                    a.href = data_type + ', ' + table_html;
                    a.download = 'exported_table_' + Math.floor((Math.random() * 9999999) + 1000000) + '.xls';
                    a.click();
                    
                    // Clear Selection
                    current_sheet.clearSelectedMarksAsync();
                })
            }

Open in new window

SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Maliki Hassani

ASKER

thanks so it isn't possible to take the array I already have and show/return a specific one?
}
return pairs[1].formattedValue;
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you for providing input to this question. I will test it and let you know if this does the trick for my desired output.  Thanks again
Perfect thank you