Skip to content

Conversation

jedib0t
Copy link
Owner

@jedib0t jedib0t commented May 22, 2018

Support sorting tables by any of the columns. Example:

    tw := table.NewWriter()
    tw.AppendHeader(Row{"#", "First Name", "Last Name", "Salary"})
    tw.AppendRows([]Row{
        {1, "Arya", "Stark", 3000},
        {11, "Sansa", "Stark", 6000},
        {20, "Jon", "Snow", 2000, "You know nothing, Jon Snow!"},
        {300, "Tyrion", "Lannister", 5000},
    }
    tw.SortBy([]SortBy{
        {Name: "Last Name", Mode: Asc},
        {Name: "First Name", Mode: Asc},
        {Number: 4, Mode: DscNumeric}, // corresponds to the "Salary" column
    })
    fmt.Println(tw.Render())

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 99.866% when pulling cb9c356 on table-sort into 844e6f1 on master.

@jedib0t jedib0t merged commit 090b0af into master May 22, 2018
@jedib0t jedib0t deleted the table-sort branch May 22, 2018 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants