FlexLayout icon indicating copy to clipboard operation
FlexLayout copied to clipboard

Adding/creating rows with addNode

Open klar-C opened this issue 3 years ago • 3 comments

Hi,

Is it possible to add/create rows with addNode? I tried to use the below function (which works fine for tabs) to actually add rows but it doesn't seem to add it.

My main goal is to generate the entire structure completely dynamically (with json being defined at most for one node at a time).

export function addNode(targetid, json) {
	let parsedjson = JSON.parse(json);
	model.doAction(
		FlexLayout.Actions.addNode(			
			parsedjson,
			targetid,
			FlexLayout.DockLocation.CENTER,
			0
		));
}

This is the json that's handed in for the model generation: image

And this is the model that the framework returns when calling model.toJson(). The tabSet element for some reason is added automatically. image

This is the json with which I'm trying to add the new row-node (the targetid that I'm using does tie to the row-node from above): image

The final format I'm trying to achieve is below (you can see that there's a row being a child of another row - and that's the part I'm not sure how to do programmatically):

{
  "global": {
    "tabEnableClose": false
  },
  "layout": {
    "type": "row",
    "children": [
      {
        "type": "row",
        "children": [
          {
            "type": "tabset",
            "weight": 75,
            "children": [
              {
                "type": "tab",
                "name": "NAME",
                "component": "NA",
                "id":  "randomid1"
              }
            ]
          },
          {
            "type": "tabset",
            "weight": 25,
            "children": [
              {
                "type": "tab",
                "name": "NAME",
                "component": "NA",
                "id": "randomid2"
              },
              {
                "type": "tab",
                "name": "NAME",
                "component": "NA",
                "id": "randomid3"
              }
            ]
          }
        ]
      }
    ]
  },
  "borders": [
    {
      "type": "border",
      "location": "left",
      "children": [
        {
          "type": "tab",
          "name": "NAME",
          "component": "NA",
          "id": "randomid4"
        },
        {
          "type": "tab",
          "name": "NAME",
          "component": "NA",
          "id": "randomid5"
        }
      ]
    }
  ]
}

klar-C avatar Apr 25 '21 01:04 klar-C

If you can do it manually then you can do it via actions. If you debug at the doAction method in the Model class then you can see the actions being used when the layout is changed, then you can perform the action manually and see how it is done.

nealus avatar May 02 '21 10:05 nealus

Any update on this? Is addNode reserved only for tabs?

MistyKuu avatar Jul 07 '21 08:07 MistyKuu

@MistyKuu The code here, as of today, suggests that the addNode action can only be used to create new tabs.

ruhullahshah avatar Sep 28 '21 09:09 ruhullahshah