Skip to content

Commit

Permalink
Do a numeric ordering if string is a number
Browse files Browse the repository at this point in the history
If the string is a number, this will make sure that strings like '3' comes
before '25. For strings that are not a numbers, the default case-insensitive
ordering will still work just like before.
  • Loading branch information
bellini666 committed Jul 30, 2015
1 parent b6b8948 commit 592d763
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions datagrid_gtk3/db/sqlite.py
Expand Up @@ -183,9 +183,13 @@ def load(self, params=None):

# ORDER BY
order_by = params.get('order_by', None)
order_by = order_by and collate(self.table.columns[order_by], 'NOCASE')
# Do a numeric ordering first, as suggested here
# (http://stackoverflow.com/a/4204641), and then a case-insensitive one
order_by = (order_by and
[self.table.columns[order_by] + 0,
collate(self.table.columns[order_by], 'NOCASE')])
if order_by is not None and params.get('desc', False):
order_by = desc(order_by)
order_by = [desc(col) for col in order_by]

# OFFSET
page = params.get('page', 0)
Expand Down

0 comments on commit 592d763

Please sign in to comment.