From 6f771796b698319de8d657b73b04464037e7a1b1 Mon Sep 17 00:00:00 2001 From: Fangjin Yang Date: Fri, 15 Mar 2013 14:28:55 -0700 Subject: [PATCH] fix js bugs with indexer console --- .../resources/static/js/druidTable-0.0.1.js | 21 +++++++++++++++---- .../resources/static/js/tablehelper-0.0.2.js | 10 ++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/server/src/main/resources/static/js/druidTable-0.0.1.js b/server/src/main/resources/static/js/druidTable-0.0.1.js index 541d437923f..7b73f315375 100644 --- a/server/src/main/resources/static/js/druidTable-0.0.1.js +++ b/server/src/main/resources/static/js/druidTable-0.0.1.js @@ -55,16 +55,24 @@ var DruidTable = function() { // build table header html += ""; + // find all unique field names + var fieldNames = {}; + for (var row in this.getRows()) { + for (var field in this.getRow(row)) { + fieldNames[field] = 1; + } + } + // build table header filters html += ""; - for (var field in this.getRow(0)) { + for (var field in fieldNames) { html += ""; } html += ""; // build table header column headings html += ""; - for (var field in this.getRow(0)) { + for (var field in fieldNames) { html += "" + field + ""; } html += ""; @@ -74,8 +82,13 @@ var DruidTable = function() { html += ""; for (var r in this.getRows()) { html += ""; - for (var field in this.getRow(r)) { - html += "" + this.getCell(r, field) + ""; + for (var field in fieldNames) { + var row = this.getRow(r); + if (row.hasOwnProperty(field)) { + html += "" + this.getCell(r, field) + ""; + } else { + html += ""; + } } html += ""; } diff --git a/server/src/main/resources/static/js/tablehelper-0.0.2.js b/server/src/main/resources/static/js/tablehelper-0.0.2.js index 57e20f1a7e4..3c060ba09a4 100644 --- a/server/src/main/resources/static/js/tablehelper-0.0.2.js +++ b/server/src/main/resources/static/js/tablehelper-0.0.2.js @@ -18,7 +18,7 @@ function buildTable(data, el, dontDisplay, table, row) { // parse JSON for (var item in data) { - setTable(data[item], el, dontDisplay, table, row); + setTable(data[item], el, dontDisplay, table, row, ""); row++; } @@ -26,16 +26,16 @@ function buildTable(data, el, dontDisplay, table, row) { initDataTable(el); } -function setTable(data, el, dontDisplay, table, row) { +function setTable(data, el, dontDisplay, table, row, fieldNamespace) { for (var field in data) { if (_.contains(dontDisplay, field)) { // do nothing } else if (Array.isArray(data[field])) { - table.setCell(row, field, JSON.stringify(data[field])); + table.setCell(row, fieldNamespace + field, JSON.stringify(data[field])); } else if (!(data[field] instanceof Object)) { - table.setCell(row, field, data[field]); + table.setCell(row, fieldNamespace + field, data[field]); } else { - setTable(data[field], el, dontDisplay, table, row); + setTable(data[field], el, dontDisplay, table, row, fieldNamespace + field + " "); } } }