Dictionaries in Jython (based on Python 2.7) can't be ordered.
I created a custom property, filteredData
on the default table and add the modified version of your code below to a button.
headers = [
'city',
'country',
'population'
]
if self.parent.getChild("Table").props.filter.results.data:
value = self.parent.getChild("Table").props.filter.results.data
data = []
# TODO: Sort the order of the columns and values
for row in value:
data.append([val for key,val in row.iteritems()])
data = system.dataset.toDataSet(headers,data)
else:
data = self.parent.parent.parent.getChild("Table").props.data
self.getSibling("Table").custom.filteredData = data
When I filter on "united" and click the button
"#NAMES"
"city","country","population"
"#TYPES"
"str","str","L"
"#ROWS","9"
"United States","Folsom","77271"
"United States","San Diego","1406630"
"United States","San Francisco","884363"
"United States","Washington, DC","658893"
"United Kingdom","London","8825001"
"United States","New York City","8622698"
"United States","Los Angeles","3884307"
"United States","Chicago","2695598"
"United States","Dallas","1317929"
So the problem is as you describe. The data produced has columns out of order.
The following code (and I'm no Python expert) seems to do the job for when there's filtered data. You'll need to add in for the unfiltered data case.
headers = [
'city',
'country',
'population'
]
if self.parent.getChild("Table").props.filter.results.data:
value = self.parent.getChild("Table").props.filter.results.data
data = []
for row in value:
fields = []
for h in headers:
fields.append(row[h])
data.append(fields)
data = system.dataset.toDataSet(headers,data)
else:
data = self.parent.parent.parent.getChild("Table").props.data
self.getSibling("Table").custom.filteredData = data