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:
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 ->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。