mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
add export to csv in table panel
This commit is contained in:
parent
5f5fcc0e04
commit
cdcc7a7172
@ -186,8 +186,29 @@ function($, _) {
|
|||||||
text += series.alias + ';' + new Date(dp[1]).toISOString() + ';' + dp[0] + '\n';
|
text += series.alias + ';' + new Date(dp[1]).toISOString() + ';' + dp[0] + '\n';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var blob = new Blob([text], { type: "text/csv;charset=utf-8" });
|
kbn.saveSaveBlob(text, 'grafana_data_export.csv');
|
||||||
window.saveAs(blob, '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) {
|
kbn.stringToJsRegex = function(str) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import kbn from 'app/core/utils/kbn';
|
||||||
import PanelMeta from 'app/features/panel/panel_meta2';
|
import PanelMeta from 'app/features/panel/panel_meta2';
|
||||||
import {transformDataToTable} from './transformers';
|
import {transformDataToTable} from './transformers';
|
||||||
|
|
||||||
@ -23,6 +24,8 @@ export class TablePanelCtrl {
|
|||||||
$scope.panelMeta.addEditorTab('Options', 'app/plugins/panel/table/options.html');
|
$scope.panelMeta.addEditorTab('Options', 'app/plugins/panel/table/options.html');
|
||||||
$scope.panelMeta.addEditorTab('Time range', 'app/features/panel/partials/panelTime.html');
|
$scope.panelMeta.addEditorTab('Time range', 'app/features/panel/partials/panelTime.html');
|
||||||
|
|
||||||
|
$scope.panelMeta.addExtendedMenuItem('Export CSV', '', 'exportCsv()');
|
||||||
|
|
||||||
var panelDefaults = {
|
var panelDefaults = {
|
||||||
targets: [{}],
|
targets: [{}],
|
||||||
transform: 'timeseries_to_columns',
|
transform: 'timeseries_to_columns',
|
||||||
@ -124,6 +127,10 @@ export class TablePanelCtrl {
|
|||||||
panelHelper.broadcastRender($scope, $scope.table, $scope.dataRaw);
|
panelHelper.broadcastRender($scope, $scope.table, $scope.dataRaw);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.exportCsv = function() {
|
||||||
|
kbn.exportTableDataToCsv($scope.table);
|
||||||
|
};
|
||||||
|
|
||||||
$scope.init();
|
$scope.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user