Skip to content

Commit b88f20e

Browse files
author
Francisco Arrieta
committed
Sort by annotation
1 parent 91ac688 commit b88f20e

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

odmtools/controller/olvDataTable.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,42 @@ def on_column_selected(self, event):
112112
self.sortColumn(event.Column)
113113

114114
def sortColumn(self, selected_column):
115-
if selected_column >= len(self.dataframe.columns):
116-
# Cannot sort by annotation code yet. Need to fix this
117-
return
115+
self.sortAscending = not self.sortAscending
118116

119117
oldSortColumnIndex = self.sortedColumnIndex
120118
self.sortedColumnIndex = selected_column
121119

122-
self.sortAscending = not self.sortAscending
123-
self.dataframe.sort_values(self.dataframe.columns[selected_column], ascending=self.sortAscending, inplace=True)
124-
125120
self._UpdateColumnSortIndicators(selected_column, oldSortColumnIndex)
126121

127-
# self.dataObjects = self.dataframe.values.tolist()
128-
self.dataObjects = self.__merge_dataframe_with_annotations()
122+
if selected_column >= len(self.dataframe.columns):
123+
self.dataObjects = self.sort_columns_by_annotation_code(reverse=self.sortAscending)
124+
else:
125+
self.dataframe.sort_values(self.dataframe.columns[selected_column], ascending=self.sortAscending, inplace=True)
126+
self.dataObjects = self.__merge_dataframe_with_annotations()
129127

130128
if self.GetItemCount():
131129
itemFrom = self.GetTopItem()
132130
itemTo = self.GetTopItem() + 1 + self.GetCountPerPage()
133131
itemTo = min(itemTo, self.GetItemCount() - 1)
134132
self.RefreshItems(itemFrom, itemTo)
135133

134+
def sort_columns_by_annotation_code(self, reverse=False):
135+
rows_with_annotation = []
136+
rows_without_annotation = []
137+
138+
column_number_of_dataframe = len(self.dataframe.columns)
139+
140+
for i in self.dataObjects:
141+
if len(i) > column_number_of_dataframe:
142+
rows_with_annotation.append(i)
143+
else:
144+
rows_without_annotation.append(i)
145+
146+
if reverse:
147+
return rows_without_annotation + rows_with_annotation
148+
else:
149+
return rows_with_annotation + rows_without_annotation
150+
136151
def onItemSelected(self, event):
137152
"""
138153

0 commit comments

Comments
 (0)