Closed iCHAIT closed 8 years ago
I think this is out of scope for terminaltables. This is something relatively easy to do in Python:
>>> from terminaltables import AsciiTable
>>> table = [['Column1', 'Column2'], ['22', '37'], ['11', '50'], ['33', '10']]
>>> print(AsciiTable(table).table)
+---------+---------+
| Column1 | Column2 |
+---------+---------+
| 22 | 37 |
| 11 | 50 |
| 33 | 10 |
+---------+---------+
>>> print(AsciiTable(table[:1] + sorted(table[1:], key=lambda i: i[0])).table)
+---------+---------+
| Column1 | Column2 |
+---------+---------+
| 11 | 50 |
| 22 | 37 |
| 33 | 10 |
+---------+---------+
>>>
Things that belong in terminaltables are those that can't be done outside of it, like column justification or enabling/disabling borders. I don't really see the value in adding sorting code here.
It would be nice if the table could be sorted according to any of the column keys.
Example -
Something like this-
table = AsciiTable(table_data, sortby="Column1")
Which would generate this -