Skip to content

Commit

Permalink
Merge pull request #4320 from GordonSmith/DGRID_NESTED_DATASETISSUE
Browse files Browse the repository at this point in the history
fix: Nested datasets not rendering correctly
  • Loading branch information
GordonSmith authored Nov 29, 2024
2 parents 4709091 + 71d18a4 commit 6d49af1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 34 deletions.
30 changes: 7 additions & 23 deletions packages/dgrid/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,15 @@ <h1>ESM Quick Test</h1>
<script type="module">
import { Table } from "./src/index.ts";

const simple = {
ND: {
columns: ["Subject", "Year 1", "Year 2", "Year 3", "Year 4"],
data: [
["English", 5, 43, 41, 92],
["English II", 17, 43, 83, 93],
["English III", 6, 43, 64, 93],
["Geography", 7, 45, 52, 83],
["Geography II", 16, 73, 52, 83],
["Geography III", 26, 83, 11, 72],
["Science", 66, 60, 85, 6],
["Science II", 46, 20, 53, 7],
["Science III", 46, 20, 38, 7],
["Math", 98, 30, 23, 13],
["Math II", 76, 30, 34, 6],
["Math III", 80, 30, 27, 8]
]
}
};

window.__table = new Table()
.target("placeholder")
.columns(simple.ND.columns)
.data(simple.ND.data)
.multiSelect(true)
.columns(["Mother", "Father", { label: "Children", columns: ["Name", "sex", "age"] }, { label: "Pets", columns: ["Name", "type"] }])
.data([
["<b>Jane</b>", "John", [["Mary", "f", 4], ["Bob", "m", 6], ["Tim", "m", 1]], [["Spot", "dog"], ["Smelly", "cat"], ["Goldie", "Fish"], ["Hammy", "Hamster"]]],
["Penelope", "Alex", [["Bill", "m", 1]], []],
["Jill", "Marcus", [], [["Flappy", "parrot"], ["Stinky", "cat"], ["Rolf", "dog"]]],
["Susan", "Robert", [["Jack", "m", 4], ["Alice", "f", 6]], []]
])
.render()
;
</script>
Expand Down
19 changes: 13 additions & 6 deletions packages/dgrid/src/RowFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function entitiesEncode(str) {
return String(str).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
}
Expand All @@ -17,6 +16,10 @@ function safeEncode(item) {
return item;
}

function isArray(obj: any): obj is any[] {
return obj instanceof Array;
}

const LINE_SPLITTER = "<br><hr class='dgrid-fakeline'>";
const LINE_SPLITTER2 = "<br><hr class='dgrid-fakeline' style='visibility: hidden'>";

Expand Down Expand Up @@ -78,9 +81,13 @@ export class RowFormatter {
for (const column of columns) {
if (column.children && row[column.leafID]) {
let childDepth = 0;
for (const childRow of row[column.leafID]) {
if (childRow instanceof Array) {
}
let childRows = [];
if (isArray(row[column.leafID])) {
childRows = row[column.leafID];
} else if (isArray(row[column.leafID].Row)) {
childRows = row[column.leafID].Row;
}
for (const childRow of childRows) {
childDepth += this.calcDepth(column.children, childRow);
}
maxChildDepth = Math.max(maxChildDepth, childDepth);
Expand All @@ -92,8 +99,8 @@ export class RowFormatter {
formatCell(column: ColumnType, cell, maxChildDepth) {
if (column.children) {
let childDepth = 0;
if (!(cell instanceof Array)) {
if (cell instanceof Object && cell.Row instanceof Array) { // Push fix in comms?
if (!isArray(cell)) {
if (isArray(cell.Row)) {
cell = cell.Row;
} else {
cell = [cell];
Expand Down
2 changes: 1 addition & 1 deletion packages/eclwatch/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"name": "index.html",
"request": "launch",
"type": "msedge",
"url": "http://localhost:5173/index.html",
"url": "http://localhost:5520/index.html",
"runtimeArgs": [
"--disable-web-security"
],
Expand Down
7 changes: 4 additions & 3 deletions packages/eclwatch/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
<h1>ESM Quick Test</h1>
<div id="placeholder"></div>
<script type="module">
import { ECLArchiveViewer } from "./src/index.ts";
import { WUResult } from "./src/index.ts";

const ESP_URL = "http://localhost:8010/";
const WUID = "W20241115-101614";

window.__widget = new ECLArchiveViewer()
const RESULT_NAME = "Result 3";
window.__widget = new WUResult()
.target("placeholder")
.baseUrl(ESP_URL)
.wuid(WUID)
.resultName(RESULT_NAME)
.render()
;
</script>
Expand Down
2 changes: 1 addition & 1 deletion packages/eclwatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"scripts": {
"clean": "rimraf --glob lib* types dist *.tsbuildinfo .turbo",
"bundle": "vite build",
"bundle-watch": "vite",
"bundle-watch": "vite --port 5520",
"gen-types": "tsc --project tsconfig.json",
"gen-types-watch": "npm run gen-types -- --watch",
"build": "run-p gen-types bundle",
Expand Down

0 comments on commit 6d49af1

Please sign in to comment.