Is it possible to filter a power table using values in a hidden column?
I have the following in a custom method on a Power Table and it seems to work fine when the filter columns are not hidden in the Power Table’s Dataset:
def filterRowsByColumnValue(self, column_name):
model = self.getTable().getModel().getActualModel()
column_count = model.getColumnCount()
i = 0
#find the index of the column by column name
while i < column_count:
name = model.getColumnName(i)
if name == column:
column_index = i
break
i=i+1
#remove any previous filters
model.clearFilters()
from com.jidesoft.grid import SingleValueFilter
#create the filter
class newFilter(SingleValueFilter):
def isValueFiltered(self, value):
if value == 0: #if this is a row that's a zero it should be filtered, so return true
return True
return False
model.addFilter(column_index, newFilter())
model.setFiltersApplied(True)
model.refresh()
However, as soon as I mark those control columns as hidden (it’s not something that I want the operators to see), the iteration of column names no longer finds an index for the column that I want to filter by.
I’m assuming that hidden columns aren’t passed into the underlying model, is that an accurate assumption, or is there a different way to get at and filter by hidden columns in the model?
That's the "source" of the problem, but it should be easy enough to work around. When you're creating your filter, couldn't you still reference the actual dataset (rather than the 'view model')? If you need to adjust column offsets back and forth, the table has helper methods:
public int columnIndexToModelIndex(int columnIndex);
public int columnIndexToDatasetIndex(int columnIndex);
public int datasetIndexToColumnIndex(int columnIndex);
You could apply the filter to a different column (that does exist), and use your newFilter class’ getters to reference the appropriate row; see getRowIndex() on AbstractTableFilter, which you would call as self.getRowIndex()/self.rowIndex in isValueFiltered():
Hello , Excuse me, I am noob programming with python and Igniton, I want to prove your code but i dont know where I have to insert it. Should I insert this code in PropertyChange, configureCell or isCellEditable?
In My project I want to filter a “Power Table” using a “Text Field”