Search

« Pagination MultipleGrids »
  Clear
Name Movie Director Movie Genre Released
Star Wars George Lucas Sci-Fi 1997
Reservoir Dogs Quentin Tarantino Thriller 1992
Airplane! David and Jerry Zucker and Jim Abrahams Slapstick 1980
@(await Html
    .SimpleGrid(Model)

    .AddColumnsForModel()

    .AddSearch("Movie Name", 
        (source, query) => source.Where(movie => movie.Name.Contains(query, StringComparison.OrdinalIgnoreCase)))

    .AddSearch("Name/Director/Genre", 
        (source, query)  => source.Where(movie =>
            movie.Name.Contains(query, StringComparison.OrdinalIgnoreCase) ||
            movie.Director.Contains(query, StringComparison.OrdinalIgnoreCase) ||
            movie.Genre.Contains(query, StringComparison.OrdinalIgnoreCase)))

    .AddSearch("Release Year", 
        (source, query) => int.TryParse(query, out int result) 
            ? source.Where(movie => movie.Released == result)
            : source.Where(movie => false))

    .AddPager(options =>
    {
        options.Botttom();
        options.RowsPerPage = 3;
    })

    .RenderAsync())

Each call to AddSearch adds an item in the dropdown.

Note that when using Entity Framework, you don't need StringComparision.OrdinalIgnoreCase as by default SQL will ignore case and specifying this in Contains may not work.