Skip to content

Instantly share code, notes, and snippets.

@pr4v33n
Created October 9, 2013 04:13
Show Gist options
  • Save pr4v33n/6896102 to your computer and use it in GitHub Desktop.
Save pr4v33n/6896102 to your computer and use it in GitHub Desktop.
// gviztablelog.js
// https://github.com/pr4v33n
// Adds a `gvizTableLog` function to window object.
// https://developers.google.com/chart/interactive/docs/reference#DataTable
(function() {
window.gvizTableLog = function(dataTable) {
var rowIndex = 0, tableData = [], columnIndex = 0, columnLabels = [];
while (columnIndex < dataTable.getNumberOfColumns()) {
columnLabels.push(dataTable.getColumnLabel(columnIndex) ||
dataTable.getColumnId(columnIndex) ||
columnIndex.toString());
columnIndex++;
}
while (rowIndex < dataTable.getNumberOfRows()) {
var rowData = {};
columnIndex = 0;
while (columnIndex < dataTable.getNumberOfColumns()) {
rowData[columnLabels[columnIndex]] = dataTable.getValue(rowIndex, columnIndex);
columnIndex++;
}
tableData.push(rowData);
rowIndex++;
}
console.table(tableData);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment