# Need help with table setup

**URL:** <https://forum.inductiveautomation.com/t/need-help-with-table-setup/3061>\
**Category:** Ignition\
**Created:** [July 5, 2011, 6:45pm UTC](https://forum.inductiveautomation.com/t/need-help-with-table-setup/3061 "2011-07-05T18:45:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [July 5, 2011, 6:45pm UTC](https://forum.inductiveautomation.com/t/need-help-with-table-setup/3061/1 "2011-07-05T18:45:15Z")

</div>

I have to setup a table that lists 4 columns: displayname, field, cost center, and poll. the data needs to be grouped by a different column named ftg ftg is a bit datatype in my table. I basically need it setup just like this attached image.

The ones on the top are ftg = 0 and the ones on the bottom are ftg = 1. I guess my problem comes in that I need to list the total count of the ftg =0 below the ftg = 0 wells and then also list total count of ftg = 1 below the ftg = 1 wells.

I need this in a table so that it can be exported to csv.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/1X/a90c3e3adfe0c70ebeb196b77ee99e5bc02d6a20.jpg)

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [July 5, 2011, 8:17pm UTC](https://forum.inductiveautomation.com/t/need-help-with-table-setup/3061/2 "2011-07-05T20:17:24Z")

</div>

Well, you have two choices: try to write a single query that returns the expected results or create the dataset in scripting. It is possible to bring back those results in a single SQL query, but it will be a nasty looking query using UNIONs. It is best to generate the results in scripting. Here is an example:[code]header = ["", “Field”, “Cost Center”, “May”]  
data = []  
res = system.db.runQuery(“SELECT \* FROM table WHERE ftg = 0”)  
data.append([“FOC Wells”, “”, “”, “”])  
for row in res:  
data.append([row[0], row[1], str(row[2]), str(row[3])])  
data.append(["", “”, “Total”, str(len(res))])

data.append(["", “”, “”, “”])

res = system.db.runQuery(“SELECT \* FROM table WHERE ftg = 1”)  
data.append([“FTG Wells”, “”, “”, “”])  
for row in res:  
data.append([row[0], row[1], str(row[2]), str(row[3])])  
data.append(["", “”, “Total”, str(len(res))])

table.data = system.dataset.toDataSet(header, data)[/code]You can create a global function in the Script Modules that can return this dataset. Add a new function like so:`def returnDS():
    import system
    ....
    return system.dataset.toDataSet(header, data)`and bind the table’s data to the following expression:`runScript("app.table.returnDS()", 10000)`The second argument can be how fast you want to run the script, in my case 10 seconds. To learn more about script modules look here:

[inductiveautomation.com/supp … odules.htm](http://www.inductiveautomation.com/support/usermanuals/ignition/script_modules.htm)

Let me know if you have any questions or if you want to try the single query idea.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [July 6, 2011, 3:08am UTC](https://forum.inductiveautomation.com/t/need-help-with-table-setup/3061/3 "2011-07-06T03:08:03Z")

</div>

thanks travis.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [July 6, 2011, 2:56pm UTC](https://forum.inductiveautomation.com/t/need-help-with-table-setup/3061/4 "2011-07-06T14:56:48Z")

</div>

Ok, got it working… but is it possible to add bolding to only certain items? I would like to Bold Ignition billing, and the location/field/cost center, and the count and actual count number

I kind of modified it a little.

header = ["", “”, “”]  
data = []  
res = system.db.runQuery(“SELECT d.displayname, f.name, d.cost\_center FROM devices d right outer join fields f on d.fieldid = f.id where d.ftg = 0 order by f.name asc”)  
data.append([“IGNITION BILLING”, “”, str(system.tag.getTagValue("[System]Client/System/CurrentDateTime"))])  
data.append(["", “”, “”])  
data.append([“Location”, “Field”, “Cost Center”])  
data.append([“FOC Wells”, “”, “”])  
for row in res:  
data.append([str(row[0]), str(row[1]), str(row[2])])  
data.append([“COUNT”, “”, str(len(res))])

data.append(["", “”, “”])

res = system.db.runQuery(“SELECT d.displayname, f.name, d.cost\_center FROM devices d right outer join fields f on d.fieldid = f.id where d.ftg = 1 order by f.name asc”)  
data.append([“FTG Wells”, “”, “”])  
for row in res:  
data.append([str(row[0]), str(row[1]), str(row[2])])  
data.append([“COUNT”, “”, str(len(res))])

event.source.getComponent(‘Table’).data = system.dataset.toDataSet(header, data)

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [July 6, 2011, 3:00pm UTC](https://forum.inductiveautomation.com/t/need-help-with-table-setup/3061/5 "2011-07-06T15:00:23Z")

</div>

You can make it bold by either using HTML or the Font Mapping for individual cells. It is better to use the Font Mapping since the HTML will get exported in the CSV. In this case you need to add an additional column that is an integer column mapping a number to a font for the Ignition billing column. You need to give the column a name and the value will be 0 for a regular font and 1 for a bold font. Once you have the extra column you can go into the table customizer and specify the font mapping for the Ignition billing column. You will also need to give the Ignition billing column a name other than empty string. There you will see at the bottom a way to map the font based on the additional column you added and you can just create the mapping. Hope that helps.
