# Java Table Component Column Sorting

**URL:** <https://forum.inductiveautomation.com/t/java-table-component-column-sorting/784>\
**Category:** Archived Topics\
**Created:** [August 20, 2008, 3:32pm UTC](https://forum.inductiveautomation.com/t/java-table-component-column-sorting/784 "2008-08-20T15:32:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![f\_adamg](https://avatars.discourse-cdn.com/v4/letter/f/bb73d2/32.png) [@f\_adamg](https://forum.inductiveautomation.com/u/f_adamg)\
**Post date:** [August 20, 2008, 3:32pm UTC](https://forum.inductiveautomation.com/t/java-table-component-column-sorting/784/1 "2008-08-20T15:32:10Z")

</div>

I was wondering if there was a property of the Table component that displayed which column was sorted: i.e. If column A,B,C was sorted, if any, and if it were ascending or descending. The purpose of this is that we have a table with 3 columns (timestamp, error type, and machine) and some users may want to have the report sorted by different columns to view the data.

Thanks,  
Adam.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [August 20, 2008, 3:52pm UTC](https://forum.inductiveautomation.com/t/java-table-component-column-sorting/784/2 "2008-08-20T15:52:20Z")

</div>

Well, I thought there was a way to do this, but it turns out there isn’t, at least not in the current version. But, when the next version comes out, you’ll be able to do this:

The following code will work in version 3.2.4 or later.

[code]# This code will print out the sort states for each table column

table = event.source.parent.getComponent(“Table”).viewport.view  
columnModel = table.columnModel  
states = {0: “Sorted Ascending”, 1: “Sorted Descending”, 2: “Not sorted”}

for x in range(columnModel.columnCount):  
column = columnModel.getColumn(x)  
header = column.headerValue  
sortMode = header.state  
print “Column %s is %s” % (header.display, states[sortMode])[/code]

---

<div class="post-metadata">

**Author:** ![f\_adamg](https://avatars.discourse-cdn.com/v4/letter/f/bb73d2/32.png) [@f\_adamg](https://forum.inductiveautomation.com/u/f_adamg)\
**Post date:** [August 20, 2008, 4:10pm UTC](https://forum.inductiveautomation.com/t/java-table-component-column-sorting/784/3 "2008-08-20T16:10:16Z")

</div>

OK sounds good. Looks easy enough once the update comes out. Thanks!

Adam
