Sorting

« Embedding Grids Pagination »
Name Released Released Sort by Released
2001: A Space Odyssey 1968 1968 Director: Stanley Kubrick
Airplane! 1980 1980 Director: David and Jerry Zucker and Jim Abrahams
Brave Heart Director: Mel Gibson
Casablanca 1942 1942 Director: Michael Curtiz
Citizen Kane 1941 1941 Director: Orson Welles
Close Encounters of the Third Kind 1997 1997 Director: Steven Spielberg
Movie with <b>bold</b> Director: This Guy
Pulp Fiction 1994 1994 Director: Quentin Tarantino
Reservoir Dogs 1992 1992 Director: Quentin Tarantino
Rocky Director: John G. Avildsen
Star Wars 1997 1997 Director: George Lucas
Terminator 1984 1984 Director: James Cameron
Terminator 2: Judgement Day 1991 1991 Director: James Cameron
The Godfather 1972 1972 Director: The Godfather
The Shawshank Redemption 1994 1994 Director: Frank Drabont
Wonder Woman 1984 2020 2020 Director:
@(await Html
    .SimpleGrid(Model)

    // by default "For" adds Sort for the column
    .AddColumnFor(movie => movie.Name)

    // turn off sorting for this column
    .AddColumn(col => col
        .For(movie => movie.Released)
        .Sortable(false))

    // this doesn't supply a Sort, so it won't be sortable
    .AddColumn(col => col
        .HeaderFor(movie => movie.Released)
        .DisplayAs(movie => movie.Released))

    // a contrived example to sort by something else than 
    // what is being displayed in the column
    .AddColumn(col => col
        .Header("Sort by Released")
        .DisplayAs(movie => $"Director: {movie.Director}")
        .SortableBy(movie => movie.Released))

    // The default/initial sort order of the grid
    // This applies even if the Grid isn't "Sortable"
    .DefaultSortBy(movie => movie.Name, SortOrder.Descending)

    // This makes the entire grid Sortable 
    // Column Headers become sort links
    .Sortable()

    .RenderAsync())

Note that adding Sortable(true) or SortableBy(...) to an individual column does not have any impact unless the entire grid is Sortable.