Search

« Pagination MultipleGrids »
  Clear
Name Movie Director Movie Genre Released
2001: A Space Odyssey Stanley Kubrick Sci-Fi 1968
@(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.