# Dynamically generated table use toggles instead of True/False?

**URL:** <https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157>\
**Category:** Ignition\
**Tags:** perspective, ignition81, scripting\
**Created:** [July 10, 2023, 7:40pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157 "2023-07-10T19:40:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 10, 2023, 7:40pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/1 "2023-07-10T19:40:08Z")

</div>

i have code on a table that is bound to a dataset which, in turn, generates the table contents. the table displays `true` or `false` for boolean values. we need toggle switches instead so we can change that state. i have no idea how, or even IF, this can this be done.

booo!! 💩  
 ![Screenshot 2023-07-10 133807](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/a/3a3b21cd4ba1e6527da9e6eef32fee8d21d0b250.png)

yaaaay!! 💯  
 ![Screenshot 2023-07-10 133936](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/c/5c66718f85411ec39f0036c43a160d7aabd7a346.png)

the bottom image, is from the prototype i built in HTML a few weeks ago.

i fully recognize this may require more information, but i don't know what to give you at this point, so let me know and i'll amend the post as needed.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 10, 2023, 7:54pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/2 "2023-07-10T19:54:28Z")

</div>

Under the `Columns` prop on the table, change render to boolean. Then under the `boolean` prop, change it to `toggle`.

[Set perspective table checkbox color - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/set-perspective-table-checkbox-color/41617)

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 10, 2023, 8:10pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/3 "2023-07-10T20:10:33Z")

</div>

ok! that's fantastic! thank you. now: how do i get it to respond to clicks so as to change it's state? i set the column prop `editable` to `true`, but that did nothing. also set `toggleSwitch` colours... nope so what am i missing?

oh, and this styleable? need the rounded pills for the design spec

---

<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:** [July 10, 2023, 8:19pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/4 "2023-07-10T20:19:44Z")

</div>

`props.cells.allowEditOn : single-click`.  
That will "open" the cell for edit and then you have to toggle the switch with a second click.  
There's a way to pass the first click though. Someone will post it.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 10, 2023, 8:24pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/5 "2023-07-10T20:24:35Z")

</div>

> [@Editing Perspective table with allowEditOn single-click still takes two clicks](https://forum.inductiveautomation.com/t/editing-perspective-table-with-allowediton-single-click-still-takes-two-clicks/30446):
>
> I have a table with two columns that are editable, a boolean and a string. I set the onCellEdit field to “single-click” however the real functionality seems to be click once to select the row, then click again to check the boolean or start writing to the text column. Is there a way to make it truly be like a work on a single click? I tried to use the onFocus and onRowclick but nether tell me what column was clicked, which would be enough for me to then programatically just select the box. An…

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 10, 2023, 8:24pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/6 "2023-07-10T20:24:38Z")

</div>

okay. yeah. i need that `single-click` to be a one shot deal. the guys we build for are not the sharpest knife in the drawer UI-wise. but that method chain will be very useful in the other parts of the UI. thank you! 😃

---

<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:** [July 10, 2023, 8:26pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/7 "2023-07-10T20:26:04Z")

</div>

See if there's any help in this:

> [@Quick help - editable Perspective Table](https://forum.inductiveautomation.com/t/quick-help-editable-perspective-table/31961/7):
>
> Hello, I am doing something similar, in my case is an int. I dont know how to do it. i have adapted the syntax to many database. And it doesn’t work. i have treated other ways but it didn’t work also.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 10, 2023, 9:32pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/8 "2023-07-10T21:32:25Z")

</div>

hm. no love so far. i can get the toggle to flip, but as soon as i select a different row, it reverts to `true`.

in more news, i found that removing all the set columns allows the table to automatically build columns based on the dataset, which is fantastic because that was going to be my next question... except that i no longer can set the display to `toggle`. so i'm really hitting a brick wall here: can't set toggle, can't style toggle, can't actually USE toggle. ☹

what is the best-practice for this scenario? we're pulling flags from a datasets which have variable number of columns of flags. i need to edit those flags and save the changes. i thought this might be straightforward, but i'm rather surprised it isn't. even the default `checkbox` doesn't work.

---

<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:** [July 10, 2023, 10:02pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/9 "2023-07-10T22:02:38Z")

</div>

> [@ian.sebryk](#):
>
> i found that removing all the set columns allows the table to automatically build columns based on the dataset,

You'll find that that won't get you far. You need to set the field property before basic functions like header title, sorting, filtering and others will work. It's not that hard to script though if you get to grips with basic Python scripting and how to set dictionary values.

> [@ian.sebryk](#):
>
> i need to edit those flags and save the changes. i thought this might be straightforward, but i'm rather surprised it isn't. even the default `checkbox` doesn't work.

The binding to the database is one-way only. It won't write back.  
To write back to the database you need to write some scripts and create the queries, preferrably using the `system.db.runPrepUpdate()` functions. It seems like a lot of work initially but that's because you're working with a database and not a spreadsheet.

Reading material:  
[https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Table#PerspectiveTable-ComponentEvents](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Table#PerspectiveTable-ComponentEvents)

The `onCellCommit` event will be of interest.  
[https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Table#PerspectiveTable-ComponentEvents](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Table#PerspectiveTable-ComponentEvents)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 11, 2023, 1:05pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/10 "2023-07-11T13:05:49Z")

</div>

> [@Transistor](#):
>
> It seems like a lot of work initiall

Err... I would correct this to, "it's _always_ a lot of work" 😬 but then again, I don't do it often and always forget where I've done it before

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 11, 2023, 2:40pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/11 "2023-07-11T14:40:37Z")

</div>

> [@Transistor](#):
>
> The binding to the database is one-way only. It won't write back.  
> To write back to the database you need to write some scripts and create the queries

i'm actually just working with _datasets_ saved to the user tag. does that make any difference? no _database_ is being used in this case: no SQL queries, just dataset references.

> [@Transistor](#):
>
> It's not that hard to script though if you get to grips with basic Python scripting and how to set dictionary values.

i know Python fairly well. still my biggest hurdle is being able to 'see' the output. i'm used to dumping contents to the console, **seeing** what i'm working with, and then setting up the exact functions i'm needing to get the data i want. for example, this script/dataset i'm working with puts square brackets around 2/3rds of the fields and has left most of the keys in the output. i don't know if that's representational or if that's the actual strings held in the dataset.

@jlandwerlen gave me some excellent advice on setting up logging, but that's a trip to the Gateway logging interface every damn time i want something simple. this feels lugubrious at best... and i think @nminchin hit it on the head: "it's _always_ hard work".

as for the toggles themselves, i followed [your post](https://forum.inductiveautomation.com/t/editing-perspective-table-with-allowediton-single-click-still-takes-two-clicks/30446/3) and it just generates this error:

```auto
Error running action 'component.onRowClick' on ian_development/ian_user_table@D/root/Table:
 Traceback (most recent call last): File "<function:runAction>", line 9, in runAction TypeError:
 'com.inductiveautomation.ignition.common.BasicDataset' object is unsubscriptable

```

and the Property Editor pane tells me that 'addtional properties aren't allowed'. 🤯

 ![tableToggleFrustrations](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/8/e81dc0e1007964be8c97aa9f1e48d01cdd2475c5.jpeg)

i am too new to understand what the heck that means. this should be a simple thing. it's a `toggle` for heaven's sake! how does it not have any useful base functionality? \*sigh\* whining aside, please help me understand how this _should_ work.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 11, 2023, 2:44pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/12 "2023-07-11T14:44:41Z")

</div>

Not sure if you've seen this post, but Paul explains debug very well,

> [@Event Configuration Print Out to debug](https://forum.inductiveautomation.com/t/event-configuration-print-out-to-debug/60091/4):
>
> @PGriffith the first thing that popped in my head was wrapper log but I couldn’t make the connection. lol. Does system.perspective.print go to the output console? And in Vision does the bare print statement suffice? Also does component script vs client script vs gateway scrip make a difference? If so, how? And how would that differ between Vision and Perspective?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 11, 2023, 2:50pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/13 "2023-07-11T14:50:39Z")

</div>

> [@ian.sebryk](#):
>
> i'm actually just working with _datasets_ saved to the user tag. does that make any difference? no _database_ is being used in this case: no SQL queries, just dataset references.

The same principle applies, mostly. The dataset you're updating in your Perspective session is a different object in memory than the dataset on the tag. You should be writing your updated dataset back to the tag and allowing your binding to retrieve that into the Perspective session.

> [@ian.sebryk](#):
>
> but that's a trip to the Gateway logging interface every damn time i want something simple.

`system.perspective.print` will send logs from Perspective to the Designer console. It has to be 'lugubrious' because of the split-brain execution model of Perspective; web browsers can't run Python/Jython, so all of your code is executing on the gateway. To avoid _even weirder_ problems, the same applies to Perspective sessions in the Designer.

> [@ian.sebryk](#):
>
> ```auto
> 'com.inductiveautomation.ignition.common.BasicDataset' object is unsubscriptable
> 
> ```

Datasets work "natively" in Perspective, but are different from JSON arrays of JSON objects. Crucially, datasets are not mutable, while JSON structures are. So that's Python telling you that `someDataset[someColumn]` is not a valid reference. You need to either A: translate your table's data from a dataset to a properly formatted JSON array, or B: translate your Python code to use `system.dataset.setValue`, which returns a _new_ dataset you'd have to write back to the tag (again, different objects in memory).

> [@ian.sebryk](#):
>
> 'addtional properties aren't allowed'.

This is just the property editor trying to tell you "don't add random elements to the defined `component.props` structure and expect them to work". You _can_ do it - I don't think we have any code anywhere that will overwrite them (outside of bindings/scripts operating on higher levels) but it's not good practice; best practice is to house your random custom properties in `component.custom` 🙂

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 11, 2023, 8:12pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/14 "2023-07-11T20:12:43Z")

</div>

okay. this is a lot to digest. as you can probably tell, i am getting a tad frustrated. the `dataset` /`pyDataset` thing is tripping me up: the one is _immutable_, the other _is_. and i'm not finding what i need to get these toggles to work as expected by our design spec. it seems such a simple thing: flip a few toggles which changes the bits so i can store changed table. this seems to either be an outlier question or nobody really knows how to make the toggles work properly _in this scenario_. 💩 there **has** to be a way.

i hope i can at least style them so they match the design spec...

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 11, 2023, 8:19pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/15 "2023-07-11T20:19:15Z")

</div>

Maybe this will help you?  
[https://docs.inductiveautomation.com/display/DOC81/Datasets](https://docs.inductiveautomation.com/display/DOC81/Datasets)

---

<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:** [July 11, 2023, 8:24pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/16 "2023-07-11T20:24:19Z")

</div>

> [@ian.sebryk](#):
>
> `dataset` /`pyDataset` thing is tripping me up: the one is _immutable_, the other _is_

No, neither is mutable. That is why all of the `system.dataset.*` methods return new datasets.

Note, as JSON object is neither a Dataset nor a PyDataset.

To get this to work, when the Cell is committed you must write that back to the data source backing the table, otherwise, when the table refreshes it's binding for any reason the data in your table will be overwritten by the original data.

So in order to best help you, can you show how you are getting the data from your tag into your table? Is it a binding? Is that binding marked as bi-directional? Is it some other method?

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 11, 2023, 9:03pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/17 "2023-07-11T21:03:22Z")

</div>

i've gone through that page a few times now. i just have to tap out on this and admit defeat. i'll have to circle around some other time. this is taking up to much time for what should be a stupidly simple thing.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 11, 2023, 9:08pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/18 "2023-07-11T21:08:36Z")

</div>

If you are able to share the view, perhaps someone could help you out.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 11, 2023, 9:11pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/19 "2023-07-11T21:11:43Z")

</div>

screenshot notwithstanding, how do i share a view??

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 11, 2023, 9:17pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/20 "2023-07-11T21:17:41Z")

</div>

Right click the view in the project browser and hit 'Export'.  
Or hold down shift and right click and 'Copy JSON' to export just the 'raw' JSON encoded structure of the view, with none of the other trappings of an Ignition project resource.

[Next page](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157.md?page=2)
