Binding tags and expressions to table cells

So when I add data to a table in the designer I can get the data looking fine, at least on the properties panel. I exported the table to see what the json would look like so I can dynamically create this table. I have another table generated in a similar way, but with static data. For the life of me this doesn't work with tags. The cells just have the json in them.

data={"Unit":{"value":unitn}
,"Driver":{"value":""}
,"Location":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"[default]"+unit+"/Location"},"type":"tag"}}
,"Status":{"binding":{"config":{"expression":"runScript(\"Faults.GetLabel\",0,tag(\"[default]\"+unit+\"/StatusIndicator\"),tag(\"[default]\"+unit+\"/Status\"))","type":"expr"}}}
,"Suc PSI":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"\"[default]\"+unit+\"/SuctionPressure\""},"type":"tag"}}
,"1st PSI":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"\"[default]\"+unit+\"/FirstStagePressure\""},"type":"tag"}}
,"2nd PSI":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"\"[default]\"+unit+\"/SecondStagePressure\""},"type":"tag"}}
,"3rd PSI":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"\"[default]\"+unit+\"/ThirdStagePressure\""},"type":"tag"}}
,"4th PSI":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"\"[default]\"+unit+\"/FourthStagePressure\""},"type":"tag"}}
,"Final PSI":{"binding":{"config":{"fallbackDelay":2.5,"mode": "expression","tagPath":"\"[default]\"+unit+\"/\"+tag(\"[default]\"+unit+\"/InterfaceDischargePressure\")+\"Pressure\""},"type":"tag"}}
,"RPMs":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"\"[default]\"+unit+\"/MotorRPMs\""},"type":"tag"}}
,"VFD Hz":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"\"[default]\"+unit+\"/VFDFrequency\""},"type":"tag"}}
,"VFD Amps":{"binding":{"config":{"fallbackDelay":2.5,"mode":"direct","tagPath":"\"[default]\"+unit+\"/VFDAmps\""},"type":"tag"}}
,"FMLA":{"value":""}
,"%LA":{"value":""}
,"Last Poll":{"binding":{"config":{"expression":"timeStampOf(\"[default]\"+unit+\"/Status\")","type":"expr"}}}
,"MaxBHP":{"value":""}
,"Frame":{"value":""}
,"County":{"value":""}
,"State":{"value":""}
,"Latitude":{"value":""}
,"Longitude":{"value":""}}
ds.append(data)
unitList.props.data = ds

Any thoughts on getting this working correctly?Thx,jake

Table JSON should look like this:

[
  {
    "city": "Helsinki",
    "country": "Finland",
    "population": 635591
  },
  {
    "city": "Jakarta",
    "country": "Indonesia",
    "population": 10187595
  },
  {
    "city": "Madrid",
    "country": "Spain",
    "population": 3233527
  }
]

I don't want the static values, but ones based on tags, and later some of the cells will use db queries.Thx,jake

Doesn't matter. @Transistor is showing you the shape you have to produce in that .data property. Which usually means a transform that mixes static and dynamic data together, yielding a list of dictionaries.

Give us more detail on what you really have for dynamic data and we can provide more guidance.

The above code is what's being used. So the first value is static and it shows correct, along with all the placeholder static values. Any of the bindings to expressions and tags and tag expressions from above just show the json output instead of what the json should generate.Thx,jake

You cannot put bindings in there. That's something you can only do in the designer, not at runtime.

You'll need to do something like this pseudo-code:

tagPaths = ["[default]" + unit + "/Location", 
            "[default]" + unit + "/StatusIndicator",
            "[default]" + unit + "/SuctionPressure"
]
tagData = system.tag.readBlocking(tagPaths)
outputData = [
  {
    "city": "Helsinki",
    "country": "Finland",
    "population": tagData[0].value
  },
  {
    "city": "Jakarta",
    "country": "Indonesia",
    "population": tagData[1].value
  },
  {
    "city": "Madrid",
    "country": "Spain",
    "population": tagData[2].value
  }
]

[/quote]

Ah, gotcha. I was hoping at runtime I could generate the json to display in the table. I'll just do what I did before and generate the static values and fill the table with a button.Thanks all

Why a button ? Bindings are cool.

Agreed, but I was told bindings don't work on the tables if I try and generate them in code. Do you know of a way to make this work?Thx,jake

If you are trying to get live tag values into a table, and the list of tags varies, you might find my tags() expression function helpful. (Note the plural.)

You would certainly want to combine with one or more of my iteration functions to build your runtime JSON.

So the code above that I showed works when I put it in the data, kind of. It shows correct in the property pane. I exported it to get the format. But for some reason when I set the data prop to the genereated dictionary it shows the json and not what the json should produce.

You can't generate bindings. But you can generate the data that those bindings would have generated.
You're overcomplicating things:
You're trying to generate bindings on rows, that would then generate the row data. Don't even try.
Instead, generate the whole data, once and for all, from a transform on the top level binding.

Let's take an example.
Say, you have 2 tags, and you want your table to have 2 rows, one for each tag.
What you're trying to do, if I understood correctly, is to generate tag bindings for each of these 2 rows.
Instead, on the table's data property, add a structure binding on these 2 tags.
Then, format the acquired data in a transform so that it corresponds to the format the table expects.

Now, this is a simplistic example. But we don't know what kind of data you're dealing with, so it's hard to be more accurate without being exhaustive, and no one has time for that.
This is why you were asked to give us more details about your data sources.

Also, I suggest taking a few steps back and telling us what your end goal is, so we can help you find a solution to an issue, instead of finding a fix to a flawed solution.

You are mixing up the idea of configuration JSON, which the designer produces in project files and exports, and values JSON, which Perspective uses to drive the display of components.

Bindings are configuration. Assigning to properties via scripting (or the output of other bindings) is values JSON, never configuration JSON.

So we have a bunch of units, that change all the time. They have data such as pressures and such. One customer wants a table format rather than our usual gauges and such. So when the view opens it will find units assigned to the customer and build a table with the tags attached to those units. It sounds like I just need to do what I do on the unit list view that works similarly, except it's all static and I have a button that nukes and regenerates the data on it.Thx,jake

Make a custom property that lists the tags that need to be displayed in your table.
Then bind the table's data property to that list, and use system.tag.readBlocking in a script transform to read them. Then format them to match what a table expects: a list of dicts, and return that list.

Then create a "table" using a flex repeater.

  • Create a single-row view that takes parameter Description, Value and Units.
  • Add three labels to the view. Bind Description and Unit's props.text to the relevant parameters. Create a tag binding on the Value props.text and point that to the parameter.

Now on the main view

  • Add the flex repeater.
  • Set the viewpath to your single-row view.
  • Add an instance of the flex repeater for each row required and set their parameters.

You can add headers, etc., to make it look like a table.

1 Like

I can't say I see the advantage of this over a regular table...

Concur. A regular table with a column view that converts a tagpath into an indirectly bound value runs rings around a flex repeater.

Agreed, but it appears the tables don't support this. Can we get someone at inductive to see about fixing this issue?