erstmal danke für die Antwort.
Ich versuch es mal mit meinen Code zu erklären:
hab alles mal in eine Debug Repo hochgeladen
SymconModule/SymconJSLiveChart at Debug · Acer90/SymconModule (github.com)
public function ReloadFormDatasets($arr, $type){
if(is_null($arr)) return;
$formData = json_decode($this->GetBuffer("ConfigurationBuffer"), true);
$axes = json_decode($this->GetBuffer("AxesBuffer"), true);
$datasets = json_decode($this->GetBuffer("DatasetsBuffer"), true);
$key = 0;
foreach ($formData["elements"] as $keyNr => $element) {
if (array_key_exists("name", $element) && $element["name"] === "Datasets") {
$key = $keyNr;
break;
}
}
//In dem bereich liegt das Problem
$id = ""; //<= hier breuchte ich den Index des auslösenden Datensatzes
switch($type){
case 0: //add
$datasets[] = $arr;
break;
case 1: //change
$datasets[$id] = $arr;
break;
case 2: //remove
unset($datasets[$id]);
break;
case 3: //update
//do nothing here
break;
}
//ende Problemes
//columns
if (is_array($axes) && count($axes) > 0) {
$colData = $formData["elements"][$key]["columns"];
$colkey = array_search("Axes", array_column($colData, 'name'));
$options_arr = array();
$options_arr[] = array("value" => "", "caption" => "--Disable Dataset--");
foreach ($axes as $item) {
if(empty($item["Ident"])){
continue;
}
$caption = $item["Title"];
if(empty($caption)) $caption = $item["Ident"];
$options_arr[] = array("value" => $item["Ident"], "caption" => $caption);
}
$formData["elements"][$key]["columns"][$colkey]["add"] = $options_arr[0]["value"];
$formData["elements"][$key]["columns"][$colkey]["edit"]["options"] = $options_arr;
}
//values
foreach ($datasets as $row => $item) {
$datasets[$row]["Dash"] = json_encode($datasets[$row]["Dash"]);
if(!array_key_exists("Axes", $item)) {
$datasets[$row]["rowColor"] = "#ff0000";
continue;
}
$axesKey = array_search($item["Axes"], array_column($axes, 'Ident'));
if(empty($item["Axes"]) || $item["Variable"] == 0 || $axesKey === false){
$datasets[$row]["rowColor"] = "#ff0000";
}
}
$this->UpdateFormField("Datasets", "columns", json_encode($formData["elements"][$key]["columns"]));
$this->UpdateFormField("Datasets", "values", json_encode($datasets));
$this->SetBuffer("ConfigurationBuffer", json_encode($formData));
$this->SetBuffer("DatasetsBuffer", json_encode($datasets));
}
form.json
{
"type": "List",
"name": "Datasets",
"caption": "Datasets",
"rowCount": 8,
"add": true,
"delete": true,
"edit": true,
"changeOrder": true,
"onAdd": " SymconJSLiveChart_ReloadFormDatasets($id, $Datasets, 0);",
"onEdit": " SymconJSLiveChart_ReloadFormDatasets($id, $Datasets, 1);",
"columns": [
{
"caption": "Type",
"name": "Type",
"width": "80px",
"add": "line",
"edit": {
"type": "Select",
"options": [
{
"caption": "Line",
"value": "line"
},
{
"caption": "Bar",
"value": "bar"
}
]
}
},
{
"caption": "Variable",
"name": "Variable",
"width": "auto",
"requiredLogging": 1,
"add": 0,
"edit": {
"type": "SelectVariable"
}
},
{
"caption": "Axe",
"name": "Axes",
"width": "150px",
"add": "",
"edit": {
"type": "Select",
"options": [
{
"caption": "--Disable Dataset--",
"value": ""
}
]
}
},
{
"caption": "Title",
"name": "Title",
"width": "300px",
"add": "",
"edit": {
"type": "ValidationTextBox"
}
},
{
"caption": "Offset",
"name": "Offset",
"width": "70px",
"add": 0,
"edit": {
"type": "NumberSpinner",
"digits": 0,
"minimum": 0
}
},
{
"caption": "Background Color",
"name": "BackgroundColor",
"width": "130px",
"add": 0,
"edit": {
"type": "SelectColor"
}
},
{
"caption": "Background Color Alpha",
"name": "BackgroundColor_Alpha",
"width": "50px",
"visible": false,
"add": 0.5,
"edit": {
"type": "HorizontalSlider",
"stepSize": 0.05,
"maximum": 1,
"minimum": 0
}
},
{
"caption": "Border Color",
"name": "BorderColor",
"width": "120px",
"add": 0,
"edit": {
"type": "SelectColor"
}
},
{
"caption": "Border Color Alpha",
"name": "BorderColor_Alpha",
"width": "50px",
"visible": false,
"add": 1.0,
"edit": {
"type": "HorizontalSlider",
"stepSize": 0.05,
"maximum": 1,
"minimum": 0
}
},
{
"caption": "Border Width",
"name": "BorderWidth",
"width": "120px",
"visible": false,
"add": 2,
"edit": {
"type": "NumberSpinner",
"digits": 0,
"minimum": 0
}
},
{
"caption": "Border Dash",
"name": "Dash",
"width": "100px",
"visible": false,
"add": "",
"edit": {
"type": "List",
"rowCount": 3,
"add": true,
"delete": true,
"sort": {
"column": "Order",
"direction": "ascending"
},
"columns": [
{
"caption": "Order",
"name": "Order",
"width": "150px",
"add": 0,
"edit": {
"type": "NumberSpinner",
"digits": 0,
"minimum": 0
}
},
{
"caption": "Length",
"name": "Length",
"width": "auto",
"add": 0,
"edit": {
"type": "NumberSpinner",
"digits": 0,
"minimum": 0,
"suffix": "px"
}
}
]
}
},
{
"caption": "HighRes",
"name": "HighRes",
"width": "150px",
"visible": false,
"add": 7,
"edit": {
"type": "Select",
"caption": "High-Res from",
"options": [
{ "caption": "minute", "value": 7 },
{ "caption": "hour", "value": 6 },
{ "caption": "day", "value": 5 },
{ "caption": "week", "value": 4 },
{ "caption": "month", "value": 3 },
{ "caption": "quarter", "value": 2 },
{ "caption": "year", "value": 1 },
{ "caption": "decade", "value": 0 }
]
}
},
{
"caption": "Stack Group",
"name": "StackGroup",
"width": "100px",
"add": 0,
"edit": {
"type": "NumberSpinner",
"digits": 0,
"minimum": 0
}
},
{
"caption": "Monotone Interpolation",
"name": "MonotoneInterpolationMode",
"width": "100px",
"add": false,
"visible": false,
"edit": {
"type": "CheckBox"
}
},
{
"caption": "Tension",
"name": "Tension",
"width": "100px",
"add": 0.0,
"visible": false,
"edit": {
"type": "NumberSpinner",
"digits": 2,
"minimum": -1,
"maximum": 1
}
},
{
"caption": "Override Point Size",
"name": "PointRadius",
"width": "50px",
"visible": false,
"add": -1,
"edit": {
"type": "NumberSpinner",
"digits": 0,
"minimum": -1,
"suffix": "px"
}
},
{
"caption": "Override Point Style",
"name": "PointStyle",
"width": "50px",
"visible": false,
"add": "",
"edit": {
"type": "Select",
"options": [
{ "caption": "-Use Default-", "value": "" },
{ "caption": "circle", "value": "circle" },
{ "caption": "cross", "value": "cross" },
{ "caption": "crossRot", "value": "crossRot" },
{ "caption": "dash", "value": "dash" },
{ "caption": "line", "value": "line" },
{ "caption": "rect", "value": "rect" },
{ "caption": "rectRounded", "value": "rectRounded" },
{ "caption": "rectRot", "value": "rectRot" },
{ "caption": "star", "value": "star" },
{ "caption": "triangle", "value": "triangle" }
]
}
},
{
"caption": "Datalabels",
"name": "datalabels_enable",
"width": "100px",
"add": false,
"edit": {
"type": "CheckBox"
}
},
{
"caption": "Datalabels Override BackgroundColor",
"name": "datalabels_BackgroundColor",
"width": "130px",
"add": -1,
"visible": false,
"edit": {
"type": "SelectColor"
}
},
{
"caption": "Datalabels Override BackgroundColor Alpha",
"name": "datalabels_BackgroundColor_Alpha",
"width": "50px",
"visible": false,
"add": 0.5,
"edit": {
"type": "HorizontalSlider",
"stepSize": 0.05,
"maximum": 1,
"minimum": 0
}
},
{
"caption": "Datalabels Override BorderColor",
"name": "datalabels_BorderColor",
"width": "120px",
"add": -1,
"visible": false,
"edit": {
"type": "SelectColor"
}
},
{
"caption": "Datalabels Override BorderColor Alpha",
"name": "datalabels_BorderColor_Alpha",
"width": "50px",
"visible": false,
"add": 1.0,
"edit": {
"type": "HorizontalSlider",
"stepSize": 0.05,
"maximum": 1,
"minimum": 0
}
},
{
"caption": "Datalabels Override FontColor",
"name": "datalabels_FontColor",
"width": "120px",
"add": -1,
"visible": false,
"edit": {
"type": "SelectColor"
}
},
{
"caption": "Datalabels Override show Prefix",
"name": "datalabels_showPrefix",
"add": false,
"visible": false,
"edit": {
"type": "CheckBox"
}
},
{
"caption": "Datalabels Override show Suffix",
"name": "datalabels_showSuffix",
"add": false,
"visible": false,
"edit": {
"type": "CheckBox"
}
}
]
},