Search

« Pagination MultipleGrids »
  Clear
Name Movie Director Movie Genre Released
Terminator James Cameron Action 1984
Terminator 2: Judgement Day James Cameron Action 1991
Wonder Woman 1984 Action 2020
@(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.