Kitchen Sink

« Basic Usage Column Selection »
  Clear
Name Movie Director Genre Name not Encoded Released
Wonder Woman 1984 ACTION Wonder Woman 1984 2020 Details
@(await Html
    .SimpleGrid(Model)

    .AddColumn(column => column
        .For(model => model.Name)
        .LinkTo(
            linkBuilder: model => $"https://www.google.com/search?q={System.Web.HttpUtility.UrlEncode(model.Name)}",
            target: "_blank")
        .Sortable()
        .Css(elements => elements.Header.AddStyle("width:21%")))

    .AddColumn(column => column
        .For(model => model.Director)
        .Css(elements => elements.Header.AddStyle("width:21%")))

    .AddColumn(column => column
        .Header("Genre")
        .DisplayAs(model => model.Genre.ToUpper())
        .SortableBy(model => model.Genre)
        .Css(elements =>
        {
            elements.Header.AddStyle("width:21%");
            elements.Item.AddStyle("font-weight:bold");
        }))

    .AddColumn(column => column
        .Header("Name not Encoded")
        .DisplayAs(model => model.Name)
        .Css(elements => elements.Header.AddStyle("width:21%"))
        .Encoded(false))

    .AddColumnFor(model => model.Released)

    .AddColumn(column => column
        .DisplayAs(model => "Details")
        .LinkTo(model =>
            $"https://www.google.com/search?q={System.Web.HttpUtility.UrlEncode(model.Name)}",
            target: "_blank",
            css: css => css.AddClass("btn btn-sm btn-primary")))

    .Css(elements => elements.Table
        .AddClass("table-striped")
        .AddClass("table-sm"))

    .Sortable()
    .DefaultSortBy(model => model.Name, SortOrder.Ascending)

    .AddSearch(
        name: "Name and Director",
        searchFilter: (source, query) =>
        {
            return source.Where(model =>
                model.Name.Contains(query, StringComparison.OrdinalIgnoreCase) ||
                (model.Director != null && model.Director.Contains(query, StringComparison.OrdinalIgnoreCase)));
        })

    .AddSearch(
        name: "Genre",
        searchFilter: (source, query) =>
        {
            query = query.Trim();
            return source.Where(model => model.Genre.Contains(query, StringComparison.OrdinalIgnoreCase));
        })

    .Options(options =>
    {
        options.MaxRows = 1000;
    })

    .AddPager(options =>
    {
        options.RowsPerPage = 5;
        options.DisplayPagerTop = true;
        options.DisplayPagerBottom = true;
        options.DisplayTotal = true;
        options.RowsPerPageOptions = new[] { 5, 10, 20, 50, 100, 1000 };
    })

    .RenderAsync()
)