Commit cdcc7a71 by matteo brancaleoni

add export to csv in table panel

parent 5f5fcc0e
......@@ -186,8 +186,29 @@ function($, _) {
text += series.alias + ';' + new Date(dp[1]).toISOString() + ';' + dp[0] + '\n';
});
});
var blob = new Blob([text], { type: "text/csv;charset=utf-8" });
window.saveAs(blob, 'grafana_data_export.csv');
kbn.saveSaveBlob(text, 'grafana_data_export.csv');
};
kbn.exportTableDataToCsv = function(table) {
var text = '';
// add header
_.each(table.columns, function(column) {
text += column.text + ';';
});
text += '\n';
// process data
_.each(table.rows, function(row) {
_.each(row, function(value) {
text += value + ';';
});
text += '\n';
});
kbn.saveSaveBlob(text, 'grafana_data_export.csv');
};
kbn.saveSaveBlob = function(payload, fname) {
var blob = new Blob([payload], { type: "text/csv;charset=utf-8" });
window.saveAs(blob, fname);
};
kbn.stringToJsRegex = function(str) {
......
......@@ -3,6 +3,7 @@
import angular from 'angular';
import _ from 'lodash';
import moment from 'moment';
import kbn from 'app/core/utils/kbn';
import PanelMeta from 'app/features/panel/panel_meta2';
import {transformDataToTable} from './transformers';
......@@ -23,6 +24,8 @@ export class TablePanelCtrl {
$scope.panelMeta.addEditorTab('Options', 'app/plugins/panel/table/options.html');
$scope.panelMeta.addEditorTab('Time range', 'app/features/panel/partials/panelTime.html');
$scope.panelMeta.addExtendedMenuItem('Export CSV', '', 'exportCsv()');
var panelDefaults = {
targets: [{}],
transform: 'timeseries_to_columns',
......@@ -124,6 +127,10 @@ export class TablePanelCtrl {
panelHelper.broadcastRender($scope, $scope.table, $scope.dataRaw);
};
$scope.exportCsv = function() {
kbn.exportTableDataToCsv($scope.table);
};
$scope.init();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment