Orchardcore admin lists

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore admin lists is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for Orchard Core 4.0 admin index views (list pages) rendered with the AdminList shape. Covers the List and Grid layouts, AdminListContext of TModel, the admin-list and admin-list-column tag helpers, column width and alignment, row display drivers placing shapes for SummaryAdmin and SummaryAdmi

How to use this skill

Skill file

Orchard Core Admin Lists

Every Orchard Core 4.0 admin page that lists items (content items, users, features, queries, workflows, layers, ...) renders them through the shared AdminList shape from OrchardCore.Admin. The shape renders the search bar, page actions, toolbar (item count, select-all, bulk actions), rows, empty message, pager, and page size selector in the layout the site (or the user) picks. Never hand-write a <ul class="list-group">, <table>, toolbar, or pager for an admin listing.

Layouts

| Enum | Values | Description |

|---|---|---|

| AdminListLayout | List (default), Grid | List renders each item's SummaryAdmin shape as a whole row. Grid renders the item's SummaryAdminGrid shape, one cell per declared AdminListColumn, on a CSS grid whose header always lines up; below 48rem of list width (container query) it stacks like a List row instead of scrolling. |

| AdminListActionsLayout | Buttons (default), Menu | Buttons renders the Actions zone as buttons plus an "Actions" dropdown for ActionsMenu. Menu renders everything in one ellipsis dropdown (a btn-sm btn-outline-secondary toggle, not wrapped in a btn-group). |

Exactly these values exist; templates can restyle them but cannot register more layouts.

Ownership

| Layer | Responsibility |

|---|---|

| Controller | Query raw items and assign an AdminListContext<TModel> with Source, Pager, and optional region shapes. Never build the list or row shapes. |

| View | Render <admin-list name="..." context="Model.List"> and declare the grid columns and presentation. |

| Row display driver | A DisplayDriver<TModel> returning shapes with a SummaryAdmin location (List) and a SummaryAdminGrid location (Grid). |

| Column provider | Optional IAdminListColumnsProvider adding or changing another list's columns. |

| AdminList shape | Resolves the layout at display time, builds each row once with that layout's display type, and renders the whole listing. |

Do not add column or cell drivers, column metadata classes, or build both representations of a row.

When to Use

| Situation | Do this |

|---|---|

| New admin page that lists items | Follow "Building a List Page" below. |

| Controller already builds rows with BuildDisplayAsync(item, updater, "SummaryAdmin") and the view loops over them | Move the raw items into AdminListContext<TModel>.Source, delete the row building, add SummaryAdminGrid locations to the driver, render <admin-list>. |

| Rows are hard-coded <li> markup in Razor | Write a DisplayDriver<TModel> for the row model first, so each row is a zone-holding shape, then build the page. |

| Adding a column to another module's list | Column provider plus a SummaryAdminGrid location in your driver (see "Extending Another Module's Columns"). |

| The page edits one entity | Not a list; see orchardcore-admin-edit-views. |

| The page arranges items rather than listing them (a tree, a canvas, a media library, widgets by zone) | Keep its own presentation. |

Building a List Page

1. Controller

model.List = new AdminListContext<Announcement>
{
    Source = announcements,
    Pager = pagerShape,
};

The view model exposes public AdminListContext List { get; set; }. The generic argument selects the display model type (also for empty collections, and for a base class or interface display manager). Rows are built only while the view renders, after the layout is resolved, so driver queries and errors happen at render time.

2. View

Import the tag helpers once (for example in Views/_ViewImports.cshtml):

@using OrchardCore.Admin
@addTagHelper *, OrchardCore.Admin.Abstractions

The view keeps the form, its hidden inputs, and the action bar, and renders the list inside the form:

<form asp-action="Index" method="post" class="no-multisubmit" data-list-management data-selected-label="@T["selected"]">
    @* Keep the hidden filter submit first: Enter in the search box triggers it. *@
    <input type="submit" name="submit.Filter" id="submitFilter" class="visually-hidden" />
    <input asp-for="Options.BulkAction" type="hidden" />
    <input type="submit" name="submit.BulkAction" class="visually-hidden" />

    @* Search input group and page buttons in a sticky action bar, see references/admin-lists-examples.md *@

    <admin-list name="Announcements" context="Model.List"
                bulk-actions="Model.Options.BulkActions"
                empty-message="@T["<strong>Nothing here!</strong> There are no announcements yet."]">
        <admin-list-list item-css-class="list-group-item" />
        <admin-list-grid>
            <admin-list-column type="Select" />
            <admin-list-column name="Title" title="@T["Title"]" position="20" />
            <admin-list-column name="Status" title="@T["Status"]" position="30" width="auto" no-wrap="true" />
            <admin-list-column type="Actions" title="@T["Actions"]" />
        </admin-list-grid>
    </admin-list>
</form>

<script asp-name="list-management" at="Foot"></script>

3. Row Display Driver

Pair every location with a display type. The shape type and template are shared; only the zone differs:

public sealed class AnnouncementDisplayDriver : DisplayDriver<Announcement>
{
    public override Task<IDisplayResult> DisplayAsync(Announcement announcement, BuildDisplayContext context)
    {
        // Row classes and attributes render on the row element in both layouts.
        if (context.DisplayType is OrchardCoreConstants.DisplayType.SummaryAdmin or OrchardCoreConstants.DisplayType.SummaryAdminGrid
            && context.Shape is Shape row)
        {
            row.Attributes["data-filter-value"] = announcement.Title?.ToLowerInvariant() ?? string.Empty;
        }

        return CombineAsync(
            View("Announcement_Checkbox_SummaryAdmin", announcement)
                .Location(OrchardCoreConstants.DisplayType.SummaryAdmin, "Checkbox:1")
                .Location(OrchardCoreConstants.DisplayType.SummaryAdminGrid, "Select:1"),
            View("Announcement_Fields_SummaryAdmin", announcement)
                .Location(OrchardCoreConstants.DisplayType.SummaryAdmin, "Content:1")
                .Location(OrchardCoreConstants.DisplayType.SummaryAdminGrid, "Title:1"),
            View("Announcement_Status_SummaryAdmin", announcement)
                .Location(OrchardCoreConstants.DisplayType.SummaryAdmin, "Tags:5")
                .Location(OrchardCoreConstants.DisplayType.SummaryAdminGrid, "Status:5"),
            View("Announcement_Buttons_SummaryAdmin", announcement)
                .Location(OrchardCoreConstants.DisplayType.SummaryAdmin, "Actions:5")
                .Location(OrchardCoreConstants.DisplayType.SummaryAdminGrid, "Actions:5"));
    }
}

Register it with services.AddDisplayDriver<Announcement, AnnouncementDisplayDriver>() in the feature that owns the list; a driver registered by a neighbouring feature leaves every row empty on sites where that feature is off. The row shape type is typeof(TModel).Name plus the display type (Announcement_SummaryAdmin), so drive a domain model or a dedicated entry record named what the shape should be called, not a *ViewModel.

The full controller, views, and templates are in references/admin-lists-examples.md.

Tag Helper Reference

<admin-list> requires name and context:

| Attribute | Purpose |

|---|---|

| name | Stable list identity used by column providers, the user's layout cookie, and alternates. Not part of the context. |

| context | The AdminListContext from the view model. |

| bulk-actions | IList<SelectListItem> for the generic toolbar; each Value is the posted action name. |

| empty-message | IHtmlContent shown when there are no rows (defaults to "No results found."). |

| show-toolbar, show-select-all, show-layout-selector | Override the matching context flags. |

| layout | Forces List or Grid. |

| item-css-class | Row classes for the List layout (default list-group-item list-group-item-action). |

| rows-* / rows-attributes | Attributes on the element wrapping the rows, e.g. rows-id="my-sortable-list". |

<admin-list-list> and <admin-list-grid> accept rows-class and item-css-class, may each be declared once, configure their layout without forcing it, and emit no HTML. For Grid, item-css-class adds to the required grid row class.

<admin-list-column> (inside admin-list or admin-list-grid):

| Attribute | Purpose |

|---|---|

| type | Select (the Select zone at position 10) or Actions (Actions and ActionsMenu zones at position end, end-aligned). Omit for a regular column. |

| name | Required for regular columns, unique ignoring case. Default zone and admin-list-column-{name} CSS class. |

| title | Localized header text; also labels stacked cells. |

| position | Placement syntax (10, 25, 35.5, end). Columns sort after all providers ran; unpositioned columns go last. |

| width | Any CSS width (20%, 12rem) or auto to hug the content. Columns without a width share the remaining space, down to 8rem each (minmax(8rem, 1fr)), so titles do not break mid-word. |

| alignment | Start (default), Center, End. |

| no-wrap | Prevents wrapping, e.g. dates and badges. |

| css-class | Extra classes on the header and cells. |

| zones | Comma- or space-separated row zones to render instead of the zone named after the column. |

`AdminListContext` Properties

| Property | Description |

|---|---|

| Source, ItemType | Raw items; AdminListContext<TModel> sets ItemType and types Source. |

| Pager, PageSize | Pager shape; a separately placed page size selector (set ShowPageSizeSelector = false on the pager to avoid rendering it twice). |

| Header | Options editor shape whose Summary and Actions zones render above the rows (content items, users). |

| Toolbar, ShowToolbar, ShowSelectAll, BulkActions, ToolbarActions | Supply a custom toolbar, or let the list build AdminListToolbar from the rows, pager, and bulk actions. |

| Search, Actions | Search-bar shape (e.g. AdminListSearch with Name, Value, Placeholder, Id, SubmitName, Autofocus, and a Filters zone) and the page buttons the layout places at the top of the list, for example Actions = await _shapeFactory.CreateAsync("LayersCreateButton") rendering a btn btn-secondary create Add Layer link. |

| Layout, ShowLayoutSelector | Force a layout (e.g. while rows are drag-sorted) and hide the selector. |

| Data | Values for column providers, e.g. ContentsAdminList.ContentTypesKey. |

| RowsAttributes, ItemCssClass, ListOptions, GridOptions, EmptyMessage | Presentation. |

The default IAdminListItemDisplayManager<TModel> delegates to IDisplayManager<TModel>; register a closed implementation for a specialized pipeline (Contents uses one that calls IContentItemDisplayManager).

Row Templates and Placement

{Model}.SummaryAdmin.cshtml renders the zones for the List layout only (the grid renders column zones directly). Every shipped row uses the same structure so lists look alike:

<div class="row g-0 align-items-center">
    <div class="col">
        <div class="title d-flex align-items-center">
            @* Checkbox zone, then <div class="summary d-flex flex-column flex-md-row list-item-search-text"> with Content, Tags, Meta *@
        </div>
        @if (Model.Description != null)
        {
            @await DisplayAsync(Model.Description)
        }
    </div>
    <div class="col-auto d-flex justify-content-end ps-2">
        @await DisplayAsync(await Factory.CreateAdminListActionsAsync((IShape)Model))
    </div>
</div>

| Zone | Renders as | Never |

|---|---|---|

| Content | The title, a plain link to the edit page | A heading (<h5>) |

| Tags, Meta | One <span class="badge ta-badge fw-normal"> per fact, with a leading icon and a title tooltip (the users list puts the email badge and UserRolesMeta role badges here) | Plain text or <span class="hint"> |

| Description | <div class="admin-list-secondary">, its own line under the title | A full-width row running under the actions |

| Actions, ActionsMenu | Through CreateAdminListActionsAsync, so the Buttons/Menu setting applies; menu items are bare <a>/<button class="dropdown-item"> | A hand-written button group, or menu items wrapped in <li> |

| Checkbox | A form-check whose label holds <span class="visually-hidden">@T["Select {0}", name]</span>, so screen readers name the checkbox | An empty label |

{
  "ContentCulture_SummaryAdmin": [
    { "displayType": "SummaryAdminGrid", "place": "Status:10" }
  ]
}

Extending Another Module's Columns

public sealed class CultureColumnsProvider : IAdminListColumnsProvider
{
    private readonly IStringLocalizer S;

    public CultureColumnsProvider(IStringLocalizer<CultureColumnsProvider> localizer)
    {
        S = localizer;
    }

    public Task PopulateAsync(AdminListColumnsContext context)
    {
        context.Columns.Add(new AdminListColumn
        {
            Name = "Culture",
            Position = "25",
            Title = S["Culture"],
            Width = AdminListColumn.AutoWidth,
        });

        return Task.CompletedTask;
    }
}
services.AddAdminListColumnsProvider<CultureColumnsProvider>(ContentsAdminList.Name);
services.AddAdminListColumnsProvider<SiteColumnsProvider>(); // global, every list

Published list names include ContentsAdminList.Name (Contents) and UsersAdminList.Name (Users); others are literal, e.g. Features, Queries, Layers, Tenants, WorkflowTypes, AdminMenus, AuditTrail, Roles, Templates. The Contents list passes ContentsAdminList.ContentTypesKey and ContentsAdminList.StereotypesKey in Data.

Configuration and Settings

Shipped defaults come from AdminListOptions, bound per tenant from OrchardCore:Admin:List:

{
  "OrchardCore": {
    "Admin": {
      "List": {
        "DefaultLayout": "Grid",
        "DefaultActionsLayout": "Menu",
        "AllowUserSelection": true
      }
    }
  }
}

Settings → Admin overrides them with List layout, Actions layout (each with Use configuration default; the actions layout also drives the edit page action bar, see orchardcore-admin-edit-views), and Let users choose the layout of a list, stored on AdminSettings:

{
  "steps": [
    {
      "name": "settings",
      "AdminSettings": {
        "ListLayout": "Grid",
        "ActionsLayout": "Menu",
        "AllowUserListLayoutSelection": true
      }
    }
  ]
}

AdminListOptions participates in the signal-backed refresh pipeline: read it through IOptionsMonitor<AdminListOptions>.CurrentValue; saving the settings applies without a shell release.

Let users choose the layout of a list is on by default (AdminSettings.AllowUserListLayoutSelection = true); the site setting is copied over AdminListOptions.AllowUserSelection, so turn it off in Settings → Admin to make every list use the site layout. With user selection on, each list shows a List/Grid selector; a click reloads with ?layout=Grid and stores the choice in a per-list cookie. Resolution order is AdminListContext.Layout, then ?layout=, then the cookie, then the site setting, then AdminListOptions.DefaultLayout. Invalid values are ignored. A list without columns falls back to List and shows no selector. A page rendering several lists (grouped by category) sets ShowLayoutSelector = false on each and creates one selector shape:

model.LayoutSelector = await shapeFactory.CreateAsync(AdminListConstants.LayoutSelectorShapeType, Arguments.From(new
{
    ListName = "Features",
}));

Alternates

| Shape | Alternates (least to most specific) |

|---|---|

| AdminList | AdminList__{Layout}, AdminList__{Name}, AdminList__{Name}__{Layout} |

| AdminListCell | AdminListCell__{Column}, AdminListCell__{Name}__{Column} |

| AdminListActions | AdminListActions__{Layout}, AdminListActions__{Name}, AdminListActions__{Name}__{Layout} (layout is Buttons or Menu) |

| AdminListToolbar | AdminListToolbar__{Layout}, AdminListToolbar__{Name}, AdminListToolbar__{Name}__{Layout} |

| AdminListSearch | AdminListSearch__{Layout}, AdminListSearch__{Name}, AdminListSearch__{Name}__{Layout} |

Examples are AdminList-Contents-Grid.cshtml and AdminListActions-Menu.cshtml. A name-only alternate such as AdminList-Users.cshtml applies to every layout of that list (opting it out of the setting); name the layout to change one mode. The list stamps ListName and ListLayout on its toolbar, search, pager, page size selector, and rows, so alternates resolve without the page passing them.

Sortable Lists

Mark the rows container with rows-* attributes (e.g. rows-id="rewrite-rules-sortable-list") and drag the rows, not their container: in Grid the container is display: contents. Use SortableJS oldDraggableIndex/newDraggableIndex, which count only rows. Force Layout = AdminListLayout.List only when the page cannot render a grid while sorting.

Gotchas

  1. Never name a view model's rows Items: Shape already exposes Items (its child shapes).
  2. An empty grid column means a shape has no SummaryAdminGrid location for that column's zone.
  3. Per-type row templates only affect List: change the grid with SummaryAdminGrid placement or AdminListCell-{List}-{Column}.cshtml.
  4. Never wrap ActionsMenu items in <li>: the dropdown sits inside the row's <li> in the List layout, the HTML parser hoists the nested <li> out, and the menu renders empty with stray links under the list.
  5. No viewport classes such as d-md-none in row Razor: the grid stacks through a container query on the list itself, because the admin sidebar makes the viewport a poor proxy for the list width.
  6. Rows are built while the view renders, from the AdminList displaying event, so driver queries and exceptions surface at render time, not in the controller.

Checking a List

Check every list page in both layouts and both actions layouts (Buttons and Menu), with rows and with none (empty message), and in a narrow window where the grid stacks its cells. In the Grid layout every declared column should render something on every row. Keep Let users choose the layout of a list on (the default) while developing to switch quickly.

Upgrading from 3.x

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.