Grid

Basic usage

Declared using the
OGrid
tag, and configured by setting the
Opt
parameter, here's a basic example that uses local data:
@inject IDbContextFactory<MyContext> cxf

@if (dinners is not null)
{
    <OGrid Opt="gopt" />
}    

@code
{
    private IEnumerable<Dinner> dinners;

    private GridOpt<Dinner> gopt;

    protected override async Task OnInitializedAsync()
    {
        initGrid();

        using var cx = cxf.CreateDbContext();        
        dinners = await cx.Dinners.Include(p => p.BonusMeal).Take(100).ToArrayAsync();             
    }

    private void initGrid()
    {
        gopt = new();
        gopt.Height = 350;
        gopt.KeyProp = m => m.Id;

        gopt.GetQuery = () => dinners.AsQueryable();

        gopt.Columns = new[] {
            new Column<Dinner>()
            {
                For = o => o.Id,
                Width = 100
            },
            new Column<Dinner>
            {
                For = o => o.Name,
                Grow = 1.2
            },
            new Column<Dinner>
            {
                For = o => o.Date,
            },
            new Column<Dinner>
            {
                Header = "Bonus Meal",
                For = o => o.BonusMeal.Name
            },
        };
    }
}

Entity Framework

In our demos a custom extension method is used (
EFData
which you can copy into your solution), it will use an
IDbContextFactory
to create a
DbContext
a for each data request, so all you'll have to specify is the initial query (e.g.
cx.Dinners
) and calls to
Include
if necessary:
gopt.EFData(cxf, cx => cx.Dinners
    .Include(p => p.Meals)
    .Include(p => p.Chef)
    .Include(p => p.BonusMeal));

GridOpt

Grid options model
BeginLoadFuncAction to execute on begin load
ColumnsGrid columns
ColumnWidthDefault column width
ContentHeightGrid content height
CssClassCSS class for the main div
DefaultKeySortDefault sort type
FilterRowEnable filter row
FrozenColumnsLeftFrozen columns on the left
FrozenColumnsRightFrozen columns on the right
GetBindValueCustom func for getting column value
GetChildrenGet row children nodes given row model, and current node level
GetKeyFuncGet get key from row model func
GetQueryGet intial query func; query before we apply FilterRow filtering, sorting, paging
GroupableDefault value for Column.Groupable
HeightGrid height
InlineEditInline Editing options
KeyGrid key property name
KeyPropset grid key
LoadLoad grid on init
LoadDataLoad data function
LoadFuncAction to execute on load
LoadLazyNodeAsyncFunction to execute when a lazy load node is expanded
MakeFooterFunction for creating a group footer
MakeHeaderFunction for creating a group header
OrderByCustom order by
PageInitial page
PageSizeInitial page size
ReorderableDefault value for Column.Reorderable
ResizableDefault value for Column.Resizable
RowClassFuncFunction to set row css class based on row model
RowClickFuncRow on click function, gets row key as parameter
SortableDefault value for Column.Sortable
StateGet grid state
StateChangeFuncFunction to execute on grid state change

Column

Grid column
BindGrid model property or properties this column is bound to, can use dot to indicate a nested property (example: Country.Name), and/or comma to bind to multiple properties (example: FirstName,LastName); binding to "Name" will make the grid orderBy "Name" when this column has sorting Ast or Desc
CssClassCss class to set for each cell in this grid column
ForSet Column.Bind using Expression;
GetStrFunction to get cell string value from the row model
GroupGrouped column
GroupableCan group this column
GrowBy default all columns (without width defined) have Grow = 1; When the grid width is greater than the sum of widths of all columns ( Width or MinWidth or grid.ColumnWidth, whichever is defined) the remaining width is distributed to all the columns according to their Grow value
HeaderHeader text
HeaderCssClassCss class to set for header cell
HiddenIs column hidden
IdColumn id, defaults to bind or header, can be autogenerated when not set or duplicate
LabelLabel, can be used instead of header or bind for the columns picker dropdown
MinWidthMin width
NoHideCannot hide this column
OptAdditional column options
RankInitial sorting rank
ReorderableCan reorder this column
ResizableCan resize this column
SortInitial column sort type
SortableCan sort this column
WidthWidth



Comments
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our cookie policy and privacy policy .