Skip to content

Commit

Permalink
Let the index of the top level header be equal to the item index (if …
Browse files Browse the repository at this point in the history
…applicable).
  • Loading branch information
arnemorken committed Nov 17, 2023
1 parent baee202 commit cbc2e4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions data/alasql/anyTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions data/mysql/anyTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cbc2e4f

Please sign in to comment.