Maliki Hassani
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].formatte dValue). It will be added to the title of my excel file. Report name: XXXX
Any ideas?
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].formatte
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();
})
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
ASKER
Perfect thank you
ASKER
}
return pairs[1].formattedValue;
}