# Centering Data of a dataset on a table

**URL:** <https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [September 6, 2023, 4:31pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821 "2023-09-06T16:31:46Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 6, 2023, 4:31pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/1 "2023-09-06T16:31:46Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/91622dd33bc46bae4d0726f5697233ec3c423271.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 6, 2023, 4:47pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/2 "2023-09-06T16:47:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 6, 2023, 5:01pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/3 "2023-09-06T17:01:31Z")

</div>

would something like this work? I can make individuals columns from it.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/7/27a882364abefad9deb7c96a2ed3794537b46f1e.png)

---

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 6, 2023, 5:12pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/4 "2023-09-06T17:12:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 6, 2023, 5:20pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/5 "2023-09-06T17:20:44Z")

</div>

There's no "column object". You'll need to jsonify the whole dataset:

```python
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:

```python
for row in value:
    row['Actual Pulled Value'] = 0
return value

```

You can add styles to your rows/cell in that script.

---

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 7, 2023, 12:44pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/6 "2023-09-07T12:44:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 7, 2023, 12:53pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/7 "2023-09-07T12:53:54Z")

</div>

> [@Alex\_Wakefield](#):
>
> there are drop downs for database and tables to point to production lines. these are input parameters into the query

Still works the same, query bindings allow you to bind query parameters to dropdowns properties.

* * *

> [@Alex\_Wakefield](#):
>
> 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.

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.

* * *

> [@Alex\_Wakefield](#):
>
> For justifying a table object, I don't think I said that

You did:

> [@Alex\_Wakefield](#):
>
> how to justify a table object

* * *

> [@Alex\_Wakefield](#):
>
> this transform is now what I'd like help with to figure out.

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.

---

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 7, 2023, 1:12pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/8 "2023-09-07T13:12:19Z")

</div>

After running the function, I get an output like this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/5/45a179eef80adc4f57075eff9cb6677e73ee533a.png)

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

---

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 7, 2023, 1:15pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/9 "2023-09-07T13:15:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 7, 2023, 1:21pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/10 "2023-09-07T13:21:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 7, 2023, 1:23pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/11 "2023-09-07T13:23:19Z")

</div>

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](https://medium.com/mission-log/design-better-data-tables-430a30a00d8c)_

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 7, 2023, 2:02pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/12 "2023-09-07T14:02:45Z")

</div>

Again:

> [@pascal.fragnoud](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 7, 2023, 3:11pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/13 "2023-09-07T15:11:40Z")

</div>

> [@Alex\_Wakefield](#):
>
> I would like to see a feature for justifying table values generated by a dataset in the future from inductive automation.

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/5/352377727066b93cce85f626eb29318e8be9d560.png)

---

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 7, 2023, 5:02pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/14 "2023-09-07T17:02:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 7, 2023, 5:21pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/15 "2023-09-07T17:21:55Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/7/07e40d562e1c942e6a3f5c11fc46bb483bbfddf2.gif)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 8, 2023, 12:25pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/17 "2023-09-08T12:25:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alex\_Wakefield](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Alex\_Wakefield](https://forum.inductiveautomation.com/u/Alex_Wakefield)\
**Post date:** [September 8, 2023, 12:33pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/18 "2023-09-08T12:33:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [September 8, 2023, 12:36pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/19 "2023-09-08T12:36:39Z")

</div>

> [@Alex\_Wakefield](#):
>
> I'd appreciate if you stopped talking to me,

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 8, 2023, 12:44pm UTC](https://forum.inductiveautomation.com/t/centering-data-of-a-dataset-on-a-table/78821/20 "2023-09-08T12:44:23Z")

</div>

> [@Alex\_Wakefield](#):
>
> why are you so rude?

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.
