fix js bugs with indexer console

This commit is contained in:
Fangjin Yang 2013-03-15 14:28:55 -07:00
parent 2a94bd508d
commit 6f771796b6
2 changed files with 22 additions and 9 deletions

View File

@ -55,16 +55,24 @@ var DruidTable = function() {
// build table header // build table header
html += "<thead>"; html += "<thead>";
// 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 // build table header filters
html += "<tr>"; html += "<tr>";
for (var field in this.getRow(0)) { for (var field in fieldNames) {
html += "<td><input type = \"text\" name=\"" + field + "\" value=\"" + field + "\" class=\"search_init\"/></td>"; html += "<td><input type = \"text\" name=\"" + field + "\" value=\"" + field + "\" class=\"search_init\"/></td>";
} }
html += "</tr>"; html += "</tr>";
// build table header column headings // build table header column headings
html += "<tr>"; html += "<tr>";
for (var field in this.getRow(0)) { for (var field in fieldNames) {
html += "<th>" + field + "</th>"; html += "<th>" + field + "</th>";
} }
html += "</tr>"; html += "</tr>";
@ -74,8 +82,13 @@ var DruidTable = function() {
html += "<tbody>"; html += "<tbody>";
for (var r in this.getRows()) { for (var r in this.getRows()) {
html += "<tr>"; html += "<tr>";
for (var field in this.getRow(r)) { for (var field in fieldNames) {
var row = this.getRow(r);
if (row.hasOwnProperty(field)) {
html += "<td " + "class=\"" + field.replace(' ', '_').toLowerCase() + "\">" + this.getCell(r, field) + "</td>"; html += "<td " + "class=\"" + field.replace(' ', '_').toLowerCase() + "\">" + this.getCell(r, field) + "</td>";
} else {
html += "<td></td>";
}
} }
html += "</tr>"; html += "</tr>";
} }

View File

@ -18,7 +18,7 @@ function buildTable(data, el, dontDisplay, table, row) {
// parse JSON // parse JSON
for (var item in data) { for (var item in data) {
setTable(data[item], el, dontDisplay, table, row); setTable(data[item], el, dontDisplay, table, row, "");
row++; row++;
} }
@ -26,16 +26,16 @@ function buildTable(data, el, dontDisplay, table, row) {
initDataTable(el); initDataTable(el);
} }
function setTable(data, el, dontDisplay, table, row) { function setTable(data, el, dontDisplay, table, row, fieldNamespace) {
for (var field in data) { for (var field in data) {
if (_.contains(dontDisplay, field)) { if (_.contains(dontDisplay, field)) {
// do nothing // do nothing
} else if (Array.isArray(data[field])) { } 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)) { } else if (!(data[field] instanceof Object)) {
table.setCell(row, field, data[field]); table.setCell(row, fieldNamespace + field, data[field]);
} else { } else {
setTable(data[field], el, dontDisplay, table, row); setTable(data[field], el, dontDisplay, table, row, fieldNamespace + field + " ");
} }
} }
} }