# Update Table display?

**URL:** <https://discourse.slicer.org/t/update-table-display/8438>\
**Category:** Development\
**Created:** [September 15, 2019, 10:32pm UTC](https://discourse.slicer.org/t/update-table-display/8438 "2019-09-15T22:32:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [September 15, 2019, 10:32pm UTC](https://discourse.slicer.org/t/update-table-display/8438/1 "2019-09-15T22:32:09Z")

</div>

Hi, i used this function to display a table node on the layout but it only works on the first table display, and not when the table is updated (same function as in SegmentStatistics module):

```
def showTable(table):
    currentLayout = slicer.app.layoutManager().layout
    layoutWithTable = slicer.modules.tables.logic().GetLayoutWithTable(currentLayout)
    slicer.app.layoutManager().setLayout(layoutWithTable)
    slicer.app.applicationLogic().GetSelectionNode().SetActiveTableID(table.GetID())
    slicer.app.applicationLogic().PropagateTableSelection()

table = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode")
table.AddColumn()
table.AddEmptyRow()
table.AddEmptyRow()

table.GetTable().GetColumn(0).SetValue(0, str(58))
table.GetTable().GetColumn(0).SetValue(1, str(20))
showTable(table)

```

Up to now it displays fine, then when i update the table there is no response (until i hide and show the table on hiearchy, leading me to think the table is properly updated but doesen’t show up due to some refreshing problem?):

```
table.GetTable().GetColumn(0).SetValue(0, str(150))
table.GetTable().GetColumn(0).SetValue(1, str(190))
showTable(table)
```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 16, 2019, 2:06am UTC](https://discourse.slicer.org/t/update-table-display/8438/2 "2019-09-16T02:06:38Z")

</div>

What you describe is not a bug but a feature. VTK data objects are optimized for bulk updates.

If you use the VTK API then you need to signal that you have finished all your modifications by calling Modified() on the data object (`table.GetTable().Modified()`).

Alternatively, you can use convenience functions of the table node, for example `table.SetCellText(0, 0, "150")`.

---

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [September 16, 2019, 2:39am UTC](https://discourse.slicer.org/t/update-table-display/8438/3 "2019-09-16T02:39:17Z")

</div>

Thank you, that worked perfectly.  
is there any difference when adding `StartModify()` and `EndModify()` as well? as in segment statistics Scripted module (i couldn’t find any documentation concerning it):

> tableWasModified = table.StartModify()  
> (… modifications…)  
> table.Modified()  
> table.EndModify(tableWasModified)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 16, 2019, 2:52am UTC](https://discourse.slicer.org/t/update-table-display/8438/4 "2019-09-16T02:52:40Z")

</div>

By calling Start/EndModify, you can update all table node properties in bulk (not just table values but also node name, column types, etc.).

---

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [September 16, 2019, 2:58am UTC](https://discourse.slicer.org/t/update-table-display/8438/5 "2019-09-16T02:58:31Z")

</div>

Then it might be handy too, Thanks for your answer.
