# 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:** ignition81, scripting, perspective\
**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:** 6\
**Page:** 2

<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:26pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/21 "2023-07-11T21:26:21Z")

</div>

this is what i inherited and the context for my learning. go nuts. for the record: only the items in my folder have been created by myself and are _not_ part of the project proper. just attempts to understand key concepts. everything else: the guy before me.

[CrossCountry\_Development\_2023-07-11\_1523.zip](https://forum.inductiveautomation.com/uploads/short-url/suQRVsue25pGmaZLhYT0QAOtLnC.zip) (41.9 KB)

---

<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:41pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/22 "2023-07-11T21:41:15Z")

</div>

You'll probably need to share the embedded views as well.

---

<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, 11:53pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/23 "2023-07-11T23:53:12Z")

</div>

See if this helps. Copy this JSON and paste it into a deep selected container.

```auto
[
  {
    "type": "ia.display.table",
    "version": 0,
    "props": {
      "selection": {
        "selectedColumn": "col1",
        "selectedRow": 1,
        "data": [
          {
            "col1": true
          }
        ]
      },
      "columns": [
        {
          "field": "col1",
          "visible": true,
          "editable": true,
          "render": "boolean",
          "justify": "auto",
          "align": "center",
          "resizable": true,
          "sortable": true,
          "sort": "none",
          "filter": {
            "enabled": false,
            "visible": "on-hover",
            "string": {
              "condition": "",
              "value": ""
            },
            "number": {
              "condition": "",
              "value": ""
            },
            "boolean": {
              "condition": ""
            },
            "date": {
              "condition": "",
              "value": ""
            }
          },
          "viewPath": "",
          "viewParams": {},
          "boolean": "toggle",
          "number": "value",
          "progressBar": {
            "max": 100,
            "min": 0,
            "bar": {
              "color": "",
              "style": {
                "classes": ""
              }
            },
            "track": {
              "color": "",
              "style": {
                "classes": ""
              }
            },
            "value": {
              "enabled": true,
              "format": "0,0.##",
              "justify": "center",
              "style": {
                "classes": ""
              }
            }
          },
          "toggleSwitch": {
            "color": {
              "selected": "",
              "unselected": ""
            }
          },
          "nullFormat": {
            "includeNullStrings": false,
            "strict": false,
            "nullFormatValue": ""
          },
          "numberFormat": "0,0.##",
          "dateFormat": "MM/DD/YYYY",
          "width": "",
          "strictWidth": false,
          "style": {
            "classes": ""
          },
          "header": {
            "title": "",
            "justify": "left",
            "align": "center",
            "style": {
              "classes": ""
            }
          },
          "footer": {
            "title": "",
            "justify": "left",
            "align": "center",
            "style": {
              "classes": ""
            }
          }
        }
      ]
    },
    "meta": {
      "name": "Table"
    },
    "position": {
      "basis": "400px"
    },
    "custom": {},
    "propConfig": {
      "props.data": {
        "binding": {
          "type": "property",
          "config": {
            "path": "this.custom.ds"
          }
        }
      },
      "custom.ds": {
        "binding": {
          "type": "tag",
          "config": {
            "mode": "direct",
            "tagPath": "[pckg_barrelwashline]_Testing/ds",
            "bidirectional": true,
            "fallbackDelay": 2.5
          }
        }
      }
    },
    "events": {
      "component": {
        "onEditCellCommit": {
          "type": "script",
          "scope": "G",
          "config": {
            "script": "\tds = self.props.data\n\tds = system.dataset.setValue(ds, event.row, event.column, event.value)\n\tself.custom.ds = ds"
          }
        }
      }
    }
  }
]

```

This is the tag I'm referencing:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/c/1c52386279753adef773c47914b64d8489beae14.png)

Editing datasets is pretty trivial in Tables once you understand how they work; it was more editing SQL tables where I was talking about it being a bit painful, as then you're having to form the INSERT/DELETE/UPDATE statements

---

<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 12, 2023, 1:07pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/24 "2023-07-12T13:07:19Z")

</div>

i just got in. i'll paste that code shortly.

i think that's kinda funny: to me, SQL is second nature and i _wish_ they'd used a database for the transactions. but i think that might be the mental roadblock. i have to do a lateral shift. 🙂

EDIT: here's a more complete export:  
[CrossCountry\_Development\_2023-07-12\_0710.zip](https://forum.inductiveautomation.com/uploads/short-url/lKyyGSn5T9PBlcGxKXeKwpNL4Yc.zip) (182.5 KB)

EDIT 2: copy/paste --\> error. it's looking for `[pckg_barrelwashline]_Testing/ds`, which i presume is the `tag` you said you were referencing... but i'm not yet familiar enough with the dialogs to know where that is supposed to be built. _but_, again presuming, i could just make my own tag with a stack of booleans to meet the requirements, yes?

---

<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 12, 2023, 2:27pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/25 "2023-07-12T14:27:27Z")

</div>

> [@ian.sebryk](#):
>
> error. it's looking for `[pckg_barrelwashline]_Testing/ds`, which i presume is the `tag` you said you were referencing

It is indeed, the only tag referenced inside of the provided JSON. He has setup a bidirectional tag binding on a custom property `ds`.

That dataset, is then referenced in a property binding on `props.data`.

You should be able to create your own dataset tag to use for testing and fix the reference in the tag binding to point to that tag.

---

<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 13, 2023, 2:49pm UTC](https://forum.inductiveautomation.com/t/dynamically-generated-table-use-toggles-instead-of-true-false/76157/26 "2023-07-13T14:49:52Z")

</div>

okay. i followed advice and spent an afternoon with Ignition support. i learned a LOT. here's what i learned that's relevant to this topic in case someone else is dealing with this issue.

1. there is a **BUG** that prevents toggles and checkboxes from being one-shotted in dynamic tables. **This bug's ID is IGN-1611**. you can add a ticket to that bug ticket to be informed when it gets fixed. it absolutely sucks, but it's out of our hands for now.

2. when working with `booleans`, **only onEditCellCommit will work**. none of the other cell events will work with `booleans`. so that is why NONE of my `system.perspective.print()` calls were working: they were never being fired. i had put all my code in the `onEditCellStart` event. which ignores `boolean` values. 🤷 as soon as i relocated the code: _whabam!_ everything worked.

3. the code to extract the toggle values turned out to be pretty straightforward, as i'd hoped. not knowing that the code was in the wrong event was driving me to drink and bashing all kinds of attempted workarounds. for completion purposes, find below the complete code, which is bound to the _table_, not the cells. the table's `data` prop is bound to the tag's dataset `value`. it works like a charm (barring the two-click bug). and here's a screen-medley of what-goes-where:  

the code below goes into the table's `onEditCellCommit` event.

```python
#
# grab all variables such as row index, column name, underlying dataset
#
selectedRow = self.props.selection.selectedRow
selectedCol = self.props.selection.selectedColumn
dataset = self.props.data # <--- or wherever you get your dataset from

#
# new value of the toggle button. takes existing value and NOTs it.
#
toggledValue = not dataset.getValueAt(selectedRow,selectedCol)

#
# alters a dataset by changing one value and recreating a new dataset
#
newDataset = system.dataset.setValue(dataset,selectedRow,selectedCol,toggledValue)

#
# write newly created dataset back to crosscountryassets dataset tag. 
#
paths = ["[<PROJECT>]Users/<PATH_TO_DATASET>"] #<--- replace with your paths, &c
values = [newDataset]
system.tag.writeBlocking(paths, values)

```

thank you all so much for your help, your patience, and your advice. i hope this is of use to someone else wanting to do this kind of thing.

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