Clearing out table content

Questions and information about using Lua scripting with Storyboard

Moderator: jamiev

Clearing out table content

Postby thomas » Thu Nov 03, 2016 12:52 pm

All,

One of the frequently asked questions we get with regards to tables, is how to manage the dynamic content of a table, for example how to expand or shrink the size of a table that is pre-configured within Storyboard.

There is a sample that demonstrates just this functionality, but it is a bit hidden in the Storyboard Samples listing (something we're hopefully changing in our next release!). The Lua sample demonstrates, among other things, how to dynamically populate table content and then how to resize the table to fit this content.

File > New > Storyboard Sample > Lua

One thing however that this sample doesn't show, is how to clear a table out entirely. If you try and set the row or column size of a table to 0, then you will see a warning issued from the Storyboard Engine indicating that this is an invalid value. Tables always have at least 1 row and column visible.

If your UI design calls for a table to be completely empty and for it to disappear entirely, then when you would have configured the row or column value to be set to 0, then instead what you should do is to set the hidden flag so that the table is completely hidden like any other control. Programmatically your Lua code, assuming that you are computing how many rows or columns you need into variables 'rows' and 'cols' might look something like:

local data ={}
if(rows > 0 and cols > 0) then
data.rows = rows
data.cols = cols
data.hidden = 0
else
data.hidden = 1
end
gre.set_table_attrs("TableName", data)

Thomas
thomas
 
Posts: 133
Joined: Mon Nov 02, 2009 4:32 pm
Location: Ottawa

Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 3 guests