I'm just trying to figure out how to justify values in a table cell once it is populated with dataset values. Since it's the "data" property that gets written to and displayed, the row/col properties are empty, and they are the only properties I could find that had "justify" attributes... so how can I center my data on the table?
Don't populate the .data property directly. Use a transform, or perhaps via a separate custom property, to process your raw data into a jsonified version that includes the necessary styling keys on the cells that need them. You can't use dataset format to deliver per-cell styling.
There's no "column object". You'll need to jsonify the whole dataset:
def jsonify_dataset(ds):
keys = ds.columnNames
return [dict(zip(keys, row)) for row in system.dataset.toPyDataSet(ds)]
I'm not entirely clear on what you're trying to do. What do you mean by "justify a table object" ?
In any case, always do as Phil says. Which, in this case, means putting a binding on the table's data property, using your named query in a query binding, and adding a transform to process the results.
Hint: If you're using a query binding, you can set the return format to json and you won't have to deal with datasets at all.
Then your whole scripts becomes this:
for row in value:
row['Actual Pulled Value'] = 0
return value
You can add styles to your rows/cell in that script.
What's not shown in this is there are drop downs for database and tables to point to production lines. these are input parameters into the query. I just used this code as an example to show I had a dataset and how I was assigning the values to the table. optimization of the code and operation is not the concern here... I'm not familiar with jsonify, but if you could elaborate a little or point me in a direction, I think I could figure it out.
For justifying a table object, I don't think I said that, but what I'm asking about is the ability to right align, left align, and center the values associated with the table's cells. From Phil, I can't do this from a dataset and have to incorporate some kind of transform... this transform is now what I'd like help with to figure out.
Still works the same, query bindings allow you to bind query parameters to dropdowns properties.
Perspective tables can take either a dataset or a list of dictionaries. You'll need to use the latter to apply styles on a per cell basis.
You did:
I've described the whole thing, including the transform code itself.
I haven't included the styles, because I can't do that for you.
But I believe there's a better way. You can probably achieve what you want through columns configuration. Check the doc page of the perspective table for the columns property.
To be honest, this just seems like a lot of extra work just to center some data considering all the other variables involved. My operators will just have to deal with it being on the left. I would like to see a feature for justifying table values generated by a dataset in the future from inductive automation.
Is this Perspective or Vision? (Add the right tag to the question title.)
If Perspective why not use the column.n.justify property?
Numeric data in tables should be right-aligned.
Numerical data is read right-to-left; that is, we compare numbers by first looking at their ones digit, then their tens, then their hundreds, and so on. This is also how most people learn arithmetic — start on the right and move left, carrying digits as you go[1]. Therefore, tables should keep numerical data right-aligned.
Textual data is read (in English) from left-to-right. Comparing textual elements is typically done by sorting into alphabetical order: if two entries start with the same letter, the second letter is used, and so on. Trying to quickly scan text can be infuriating if it’s not left-aligned.
Headers, generally, should carry whatever alignment their data has. This keeps the vertical lines of the table clean, and provides consistency and context.
Center alignment causes the lines of the table to become “ragged,” which makes it much harder to scan entries, often necessitating extra dividers and graphical elements. Source: Design Better Data Tables. Poor tables. Where did they go wrong? | by Matthew Ström | Mission Log | Medium
The feature already exists, you're just not using it.
Add an array element for each column to the table.props.columns property, then add the column name to the field for each column. This will give you the ability to configure each column as you wish, including justification and alignment.
Note: Any style included with the data for the cell will override this.
I tried that with my first response. I made an array and tried to make a column out of it, but it didn't like it. It said it wanted an object instead of an array. Is there a different way to do it?
This is what @pascal.fragnoud has been trying to tell you. You don't need to "make an array". The table has the data, if you need to do something on a cell by cell basis, then okay, I can help you with a transform that can do that.
If you just want something that formats a column as a whole, which is what I think you're wanting. Here is a demo to show what I am meaning.
Because I'm an angry and bitter man who only learned to talk to computers, not to people.
Or maybe because the post I was answering to didn't show much appreciation for the effort @lrose put into giving you a solution.