From e17b1548e8f6336dfd11529fbc1125ab3062b711 Mon Sep 17 00:00:00 2001 From: slqgsm Date: Fri, 29 Jul 2016 20:21:59 +0000 Subject: [PATCH] Release there were some issues with the way removing columns was being implemented. So I decided to scrap that, and go for just having a hidden column style. This is what @madshall did in his enhanced table pull request, so this is basically the hidden column style feature form his pull request. --- public/app/plugins/panel/table/editor.ts | 1 + public/app/plugins/panel/table/module.html | 2 +- public/app/plugins/panel/table/module.ts | 1 - public/app/plugins/panel/table/renderer.ts | 13 ++++++++++ .../app/plugins/panel/table/transformers.ts | 24 ++----------------- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/public/app/plugins/panel/table/editor.ts b/public/app/plugins/panel/table/editor.ts index 65c8b51cab8..027411126aa 100644 --- a/public/app/plugins/panel/table/editor.ts +++ b/public/app/plugins/panel/table/editor.ts @@ -39,6 +39,7 @@ export class TablePanelEditorCtrl { {text: 'Number', value: 'number'}, {text: 'String', value: 'string'}, {text: 'Date', value: 'date'}, + {text: 'Hidden', value: 'hidden'} ]; this.fontSizes = ['80%', '90%', '100%', '110%', '120%', '130%', '150%', '160%', '180%', '200%', '220%', '250%']; this.dateFormats = [ diff --git a/public/app/plugins/panel/table/module.html b/public/app/plugins/panel/table/module.html index 0c69fe6cb9b..8d6f604dc56 100644 --- a/public/app/plugins/panel/table/module.html +++ b/public/app/plugins/panel/table/module.html @@ -4,7 +4,7 @@ -
+
{{col.text}} diff --git a/public/app/plugins/panel/table/module.ts b/public/app/plugins/panel/table/module.ts index e4ddf67e23d..86847a01aac 100644 --- a/public/app/plugins/panel/table/module.ts +++ b/public/app/plugins/panel/table/module.ts @@ -94,7 +94,6 @@ class TablePanelCtrl extends MetricsPanelCtrl { onDataReceived(dataList) { this.dataRaw = dataList; this.pageIndex = 0; - this.panel.columns = []; // automatically correct transform mode based on data if (this.dataRaw && this.dataRaw.length) { diff --git a/public/app/plugins/panel/table/renderer.ts b/public/app/plugins/panel/table/renderer.ts index 819471c9470..7c2270df8b9 100644 --- a/public/app/plugins/panel/table/renderer.ts +++ b/public/app/plugins/panel/table/renderer.ts @@ -45,6 +45,12 @@ export class TableRenderer { return this.defaultCellFormater; } + if (style.type === 'hidden') { + return v => { + return undefined; + }; + } + if (style.type === 'date') { return v => { if (_.isArray(v)) { v = v[0]; } @@ -119,6 +125,13 @@ export class TableRenderer { widthHack = '
' + this.table.columns[columnIndex].text + '
'; } + if (value === undefined) { + style = ' style="display:none;"'; + this.table.columns[columnIndex].hidden = true; + } else { + this.table.columns[columnIndex].hidden = false; + } + return '' + value + widthHack + ''; } diff --git a/public/app/plugins/panel/table/transformers.ts b/public/app/plugins/panel/table/transformers.ts index 53e19823d0b..b1cc644790e 100644 --- a/public/app/plugins/panel/table/transformers.ts +++ b/public/app/plugins/panel/table/transformers.ts @@ -142,7 +142,6 @@ transformers['table'] = { if (!data || data.length === 0) { return []; } - return data[0].columns; }, transform: function(data, panel, model) { if (!data || data.length === 0) { @@ -153,27 +152,8 @@ transformers['table'] = { throw {message: 'Query result is not in table format, try using another transform.'}; } - var i,j,k, entry; - - if (panel.columns.length === 0) { - for (i = 0; i < data[0].columns.length; i++) { - panel.columns.push({ text: data[0].columns[i].text, value : data[0].columns[i].text}); - } - } - var indices = []; - for (i = 0; i < panel.columns.length; i++) { - var column = _.findWhere(data[0].columns, { "text" : panel.columns[i].text }); - indices.push(_.indexOf(data[0].columns, column)); - model.columns.push(column); - } - - for (i = 0; i < data[0].rows.length; i++) { - entry = []; - for (j = 0; j < indices.length; j++) { - entry.push(data[0].rows[i][indices[j]]); - } - model.rows.push(entry); - } + model.columns = data[0].columns; + model.rows = data[0].rows; } };