1 Star 0 Fork 0

QianXun-Studio / Grid.Blazor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Data_annotations.md 2.42 KB
一键复制 编辑 原始数据 按行查看 历史
Gustavo Navarro 提交于 2019-10-30 16:24 . Add extended sorting and grouping

GridMvc for ASP.NET Core MVC

Data annotations

Index

You can customize grid and column settings using data annotations. In other words, you can mark properties of your model class as grid columns, specify column options, call AutoGenerateColumns method, and GridMvc will automatically create columns as you describe in your annotations.

There are some attributes for this:

  • GridTableAttribute: applies to model classes and specify options for the grid (paging options...)
  • GridColumnAttribute: applies to model public properties and configure a property as a column with a set of properties
  • GridHiddenColumn: applies to model public properties and configures a property as a hidden column
  • NotMappedColumnAttribute: applies to model public properties and configures a property as NOT a column. If a property has this attribute, GridMvc will not add that column to the column collection

For example a model class with the following data annotations:

    [GridTable(PagingEnabled = true, PageSize = 20)]
    public class Foo
    {
        [GridColumn(Title = "Name title", SortEnabled = true, FilterEnabled = true)]
        public string Name { get; set; }

        [GridColumn(Title = "Active Foo?")]
        public bool Enabled { get; set; }

        [GridColumn(Title = "Date", Format = "{0:dd/MM/yyyy}")]
        public DateTime FooDate { get; set; }

        [NotMappedColumn]
        public byte[]() Data { get; set; }
    }

describes that the grid table must contain 3 columns (Name, Enabled and FooDate) with custom options. It also enables paging for this grid table and page size as 20 rows.

Finnaly you can render this table in the view:

    @await Html.Grid(Model).AutoGenerateColumns().RenderAsync()

GridMvc will generate columns based on your data annotations when the AutoGenerateColumns method is invoked.

You can add custom columns after or before this method is called, for example:

    @await Html.Grid(Model).AutoGenerateColumns().Columns(columns=>columns.Add(foo=>foo.Child.Price)).RenderAsync()

You can also overwrite grid options. For example using the WithPaging method:

    @await Html.Grid(Model).AutoGenerateColumns().WithPaging(10).RenderAsync()

<- Multipile grids on the same page | Render button, checkbox, etc. in a grid cell ->

1
https://gitee.com/fan0217/Grid.Blazor.git
git@gitee.com:fan0217/Grid.Blazor.git
fan0217
Grid.Blazor
Grid.Blazor
master

搜索帮助