Created
May 21, 2020 23:16
-
-
Save robcrock/4ba4894385c2c3ab5f0e6c7a24a7bef4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extension Debugging | |
// open /Applications/Tableau\ Desktop\ 2019.4.app --args --remote-debugging-port=8696 | |
// Chromium link | |
// http://localhost:8696 | |
// Wrap everything in an anonymous function to avoid polluting the global namespace | |
(function () { | |
// Use the jQuery document ready signal to know when everything has been initialized | |
$(document).ready(function () { | |
// Tell Tableau we'd like to initialize our extension | |
tableau.extensions.initializeAsync().then(function () { | |
// Once the extension is initialized, ask the user to choose a sheet | |
// showChooseSheetDialog(); | |
loadSelectedMarks('table'); | |
// initializeButtons(); | |
}); | |
}); | |
function loadSelectedMarks(worksheetName) { | |
// Get the worksheet object we want to get the selected marks for | |
const worksheet = getSelectedSheet(worksheetName); | |
worksheet.getUnderlyingDataAsync().then(dataTable => { | |
// Create an array from the column names | |
const columns = dataTable.columns.map(column => column.fieldName); | |
// Create an array of objects. | |
// One object for each row. | |
const dataArray = dataTable.data.map((row) => { | |
let rowObj = {}; | |
row.map((col, i) => { | |
rowObj[columns[i]] = col.value; | |
}) | |
return rowObj | |
}) | |
console.log(JSON.stringify(dataArray)); | |
}); | |
// Set our title to an appropriate value | |
$('#selected_marks_title').text(worksheet.name); | |
} | |
function getSelectedSheet(worksheetName) { | |
// Go through all the worksheets in the dashboard and find the one we want | |
return tableau.extensions.dashboardContent.dashboard.worksheets.find(function (sheet) { | |
return sheet.name === worksheetName; | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment