Hey there everyone. 
I have a PowerTable on a Popup dialog. The following code runs on the PowerTableās initialize function:
import com.jidesoft.filter.AbstractFilter
Determine Laptop Name from LaptopID
newData = system.db.runPrepQuery(āSELECT [Name] FROM [LaptopAsset] WHERE [id]=?ā, [self.parent.InputParameterLaptopID])
for row in newData:
sLaptopName = row[āNameā]
Apply the filters
oTable = self.table
oTable.setAutoCreateRowSorter(1)
oTableHeader = oTable.getTableHeader()
oTableHeader.clearFilters()
oTableHeader.setShowFilterIcon(1)
oTableHeader.setShowSortArrow(1)
oTableHeader.setAutoFilterEnabled(1)
oActualModel = oTable.getRowSorter().getModel().getActualModel()
oActualModel.clearFilters()
oActualModel.addFilter(0, com.jidesoft.filter.EqualFilter(āLaptopNameā, sLaptopName))
oActualModel.setFiltersApplied(1)
Specify the focus
self.requestFocusInWindow()
The code successfully filters the dataset⦠and displays the proper tableheader icons (because of setShowFilterIcon and SetShowSort Arrow)⦠sorting tableheader icon works great, but when I select āAllā from the tableheader filter choices, it doesnāt āunapplyā/remove the programmatically applied filter⦠I have struggled for a couple of days with the Jtable docs and tried many things, but canāt figure out what Iām doing wrong. Any help is appreciated. Thanks in advance!
Frank.
model = self.getTable().getModel().getActualModel()
from com.jidesoft.grid import SingleValueFilter
class newFilter(SingleValueFilter):
def isValueFiltered(self, value):
return True if value == target.data.getValueAt(row, 4) else False
model.addFilter(3, newFilter())
model.setFiltersApplied(True)
model.refresh()
Iāve used this code before to successfully apply a filter (shows the filter icon in the table header correctly), and it also allows it to be removed by selecting āAllā from the dropdown; I suspect that the EqualFilter
youāre using doesnāt do everything necessary to interact with the table.
1 Like
That did it! Weird how we needed to derive our own filter⦠Thanks ever so much! Cheers! 
Just a note for future reference, you do need to have āFilterableā enabled to get the icon in the table header. Otherwise it just filters without icon.

But Iām wondering if there would be something similar for grouping. Iāve found documentation about grouping on Jide tables, but I canāt get it to work in python.
https://www.jidesoft.com/products/JIDE_Grids_Developer_Guide.pdf#page=94
1 Like
Can you help to clarify how this works?
I canāt seem to get this runā¦
And how do we customize the filters?
Hereās an outline. Create one custom method for each filter configuration in the power table you wish to script.
def setFilter(self, col, target):
model = self.getTable().getModel().getActualModel()
model.clearFilters()
from com.jidesoft.grid import SingleValueFilter
class newFilter(SingleValueFilter):
def isValueFiltered(self, value):
return bool( value != target )
model.addFilter(col, newFilter())
model.setFiltersApplied(True)
model.refresh()
For each column you need to tailor the SingleValueFilter return logic based on the columnās data type and values. In order to filter using two columns you need to declare two classes, and so forth. Note the inequality in the isValueFiltered() logic above i.e. (value != target). First I tried as @PGriffith indicated but that yields the logical complement of the desired filtration hence the negation.
Finally script the filters in the other component that serves as the GUI for setting the filters. In my case I have another power table that summarizes the main raw data set. In the summary tableās extension function it goes something like this.
def onMousePress(self, rowIndex, colIndex, colName, value, event):
root = self.parent
table = root.getComponent('Power Table Raw Data')
if colIndex == 0: table.setFilter(colIndex,value)
documentation link: http://www.jidesoft.com/javadoc/com/jidesoft/grid/FilterableTableModel.html
3 Likes