Centering Data of a dataset on a table

Hello,

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?

Doesn't mean a lot, but here's the code:
image

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.

would something like this work? I can make individuals columns from it.
image

I did that and it doesn't like it because the data is an array instead of a column object.

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.

1 Like

Hey Pascal,

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.

After running the function, I get an output like this:
image

how do I use this to populate the table and it be centered, I'll see if the binding route works in the meantime.

binding presents the same problem. Can't justify the returned dataset.

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.

Thanks for the help

Questions:

  1. Is this Perspective or Vision? (Add the right tag to the question title.)
  2. 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

1 Like

Again:

2 Likes

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.

image

2 Likes

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.

justify

3 Likes

There can only be 2 ways this works for us and not for you:

  1. ignition doesn't like you specifically
  2. you're doing something wrong

Show us what you're doing so we can help you fix it.

1 Like

why are you so rude? I'd appreciate if you stopped talking to me like that, and yea I think I figure it out.

Be careful what you ask for or you might get it.

5 Likes

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.

Pick whichever reason you prefer.

1 Like