From cbc2e4f6876262d996367624056a79f14eb99367 Mon Sep 17 00:00:00 2001 From: Arne Morken Date: Fri, 17 Nov 2023 12:55:35 +0100 Subject: [PATCH] Let the index of the top level header be equal to the item index (if applicable). --- data/alasql/anyTable.js | 11 +++++++---- data/mysql/anyTable.php | 15 +++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/data/alasql/anyTable.js b/data/alasql/anyTable.js index 4d809c7..ebce3f8 100644 --- a/data/alasql/anyTable.js +++ b/data/alasql/anyTable.js @@ -556,17 +556,20 @@ anyTable.prototype.prepareData = function(inData) { //console.log("inData before prepare:"); console.log(inData); // Make room for a top level header - let data = {"data": { "+0": {} }}; + let topidx = "+0"; + if (this.id || this.id === 0) + topidx = this.id; + let data = {"data": { [topidx]: {} }}; // Find and set the header let hdr = this.findHeader(inData); if (hdr && hdr != "") { - data["data"]["+0"]["head"] = "group"; - data["data"]["+0"]["group_name"] = hdr; + data["data"][topidx]["head"] = "group"; + data["data"][topidx]["group_name"] = hdr; } // Set data - data["data"]["+0"]["data"] = inData; + data["data"][topidx]["data"] = inData; // Set link types data["types"] = this.linking; diff --git a/data/mysql/anyTable.php b/data/mysql/anyTable.php index 4cffe42..b455e40 100644 --- a/data/mysql/anyTable.php +++ b/data/mysql/anyTable.php @@ -1756,23 +1756,26 @@ public function prepareData(&$inData) { //vlog("inData before prepare:",$inData); // Make room for a top level header - $data = array("data" => array("+0" => null)); + $topidx = "+0"; + if (($this->mId || $this->mId === 0) && $this->mId != "") + $topidx = "+".$this->mId; + $data = array("data" => array($topidx => null)); // Find and set the header $hdr = $this->findHeader($inData); if (isset($hdr) && $hdr != "") { if (($this->mId || $this->mId === 0) && $this->mId != "") { - $data["data"]["+0"]["head"] = $this->mType; - $data["data"]["+0"][$this->mNameKey] = $hdr; + $data["data"][$topidx]["head"] = $this->mType; + $data["data"][$topidx][$this->mNameKey] = $hdr; } else { - $data["data"]["+0"]["head"] = "group"; - $data["data"]["+0"]["group_name"] = $hdr; + $data["data"][$topidx]["head"] = "group"; + $data["data"][$topidx]["group_name"] = $hdr; } } // Set data - $data["data"]["+0"]["data"] = $inData; + $data["data"][$topidx]["data"] = $inData; // Set link types $data["types"] = $this->mLinking;